From-Scratch Build · Computer Vision
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.
What it is
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
A handful of ROS pieces do all the work. Here is each one's role.
The robotics framework. The camera publishes raw images to a ROS topic, and the calibration tools subscribe to it — everything talks over topics.
The interactive node that detects the checkerboard, gathers enough varied views, and computes the camera's intrinsic parameters.
Takes the calibration and the raw feed and publishes rectified, distortion-corrected images for the rest of the system to use.
A printed pattern of known geometry — an 8×6 grid of inner corners with 30 mm squares — that serves as the ground truth.
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.
The ROS topic that carries the calibration alongside the image stream, so any consumer knows the camera's true optics.
The process
Calibration is a short, repeatable procedure. Each step has a clear purpose:
Install the camera_calibration and image_proc packages for your ROS distribution, and confirm the camera is publishing raw images to a topic.
Print an 8×6 checkerboard with 30 mm squares on any standard printer — flat and rigid matters more than fancy.
Launch the calibration node, telling it the board size, the square size, and which image and camera topics to use.
Move the board through many angles, distances and corners of the frame; the GUI fills its progress bars as it gathers enough variety.
When the result is good, save the calibration and commit it — pushing the new parameters onto the camera_info topic.
Run image_proc in the camera's namespace; it subscribes to the raw feed and publishes clean, undistorted images.
Reusing the result
Calibrating once is only useful if the result survives a restart. The parameters live in a YAML file and get reloaded automatically:
camera_info topic every time the camera starts.Reflection
camera_info means any downstream node automatically knows the camera's true optics — no hand-passed config.