← all builds

From-Scratch Build · Computer Vision

Camera Calibration Guide

A hands-on guide to teaching a camera its own optics — measuring the distortion in its lens with a printed checkerboard, then rectifying every frame in ROS. Built from scratch to learn why raw camera images lie, and how to make them tell the truth.

ROScamera_calibrationimage_proc CheckerboardIntrinsics

What it is

Why a camera needs calibrating

Every real lens bends light imperfectly. Straight lines bow outward near the edges, and the image you capture is a subtly warped version of the scene. For a person that's invisible; for a robot trying to measure distances or locate an object, that distortion is a lie baked into every frame. Camera calibration is the process of measuring exactly how a given lens distorts, so the software can undo it.

This guide calibrates a camera using ROS, the robotics middleware. You show the camera a printed checkerboard from many angles; because the board's geometry is known perfectly, the calibration tool can work backwards to recover the camera's intrinsic parameters — focal length, optical centre and distortion coefficients. Those numbers then let every future image be straightened, or rectified.

The core idea I wanted to learn: a known pattern is a measuring stick for optics. Because we know the checkerboard's true squares, any difference between where the corners should appear and where they actually appear reveals the lens's distortion exactly.

The stack

Tools under the hood

A handful of ROS pieces do all the work. Here is each one's role.

middleware

ROS

The robotics framework. The camera publishes raw images to a ROS topic, and the calibration tools subscribe to it — everything talks over topics.

tool

camera_calibration

The interactive node that detects the checkerboard, gathers enough varied views, and computes the camera's intrinsic parameters.

tool

image_proc

Takes the calibration and the raw feed and publishes rectified, distortion-corrected images for the rest of the system to use.

target

Checkerboard

A printed pattern of known geometry — an 8×6 grid of inner corners with 30 mm squares — that serves as the ground truth.

output

YAML + launch file

Calibration is saved as a YAML file and loaded back via a launch file, so the parameters reach the camera_info topic on every startup.

topic

camera_info

The ROS topic that carries the calibration alongside the image stream, so any consumer knows the camera's true optics.

The process

From checkerboard to corrected image

Calibration is a short, repeatable procedure. Each step has a clear purpose:

  1. Prepare

    Install the camera_calibration and image_proc packages for your ROS distribution, and confirm the camera is publishing raw images to a topic.

  2. Print the target

    Print an 8×6 checkerboard with 30 mm squares on any standard printer — flat and rigid matters more than fancy.

  3. Run the calibrator

    Launch the calibration node, telling it the board size, the square size, and which image and camera topics to use.

  4. Capture views

    Move the board through many angles, distances and corners of the frame; the GUI fills its progress bars as it gathers enough variety.

  5. Save and commit

    When the result is good, save the calibration and commit it — pushing the new parameters onto the camera_info topic.

  6. Rectify

    Run image_proc in the camera's namespace; it subscribes to the raw feed and publishes clean, undistorted images.

Reusing the result

Loading calibration on every boot

Calibrating once is only useful if the result survives a restart. The parameters live in a YAML file and get reloaded automatically:

Reflection

What building this guide taught me