
ROS 2 camera calibration connects pixels to viewing rays; TF2 connects those rays or measured 3D points to the robot. First estimate the camera’s intrinsics and distortion, publish matching CameraInfo, and distinguish raw from rectified pixels. Then use the optical-frame convention and the transform at the observation time. A monocular pixel alone has no metric depth: transforming its coordinates does not make it a 3D detection.
Reviewed 3 December 2026: calibration workflow, CameraInfo fields, frame direction and the Python example below. Documentation scope: ROS 2 Jazzy. The downloadable geometry fixture ran locally with the Python standard library; no ROS runtime, physical camera or robot was tested.
Use the calibration workflow, CameraInfo checklist, optical-frame mapping, reprojection checks, TF2 integration, or downloadable worked example according to the stage you need to verify.
1. Why Your Robot is Blind Without Calibration: The World of Intrinsic Parameters
A camera image tells you where light reached the sensor. To associate a pixel with a direction in space, you need a camera model: focal lengths, principal point and a distortion model. Intrinsic calibration estimates those parameters from known geometry observed across multiple images. It does not, by itself, locate the camera relative to base_link.
The Role of the Checkerboard: Your Robot’s Eye Chart

A checkerboard provides known corner positions. Its inner corners, physical square size, image resolution and image topic must match the calibration setup. Varying the board’s position and tilt gives the estimator different views of the same geometry; repeatedly showing one centered, front-facing board provides much less information.
A practical monocular calibration workflow
Fix the intended camera mode and measure the board. Record resolution, lens/focus settings, inner-corner count and square size in metres.
Confirm that the driver publishes raw images. For the official tutorial’s 8 × 6 inner corners and 0.108 m squares, its example command is:
1
ros2 run camera_calibration cameracalibrator --size 8x6 --square 0.108 image:=/camera/image_raw camera:=/camera
Cover different image regions, distances and tilts. Calibrate, inspect the corrected view, and save the parameters. Loading them into a driver depends on that driver’s supported interface.
Check the image and
CameraInfotogether. Publishing calibration metadata alone does not rectify image pixels; rectification is a separateimage_procstep.
The command and acquisition procedure follow the official Jazzy monocular calibration tutorial. Replace its board dimensions and topic names with your own; this is a documented procedure, not a camera run performed for this article.

Schematic: calibration estimates intrinsics; a camera driver publishes the corresponding metadata; image processing can then rectify the image.
What to check in CameraInfo
| Field | Meaning and check |
|---|---|
header.stamp, header.frame_id | Image acquisition time and camera optical frame. |
width, height | Calibration image dimensions; account for the actual capture mode. |
distortion_model, d | Named distortion model and its coefficients. Five plumb_bob values are not a universal lens model. |
k | Raw-image intrinsic matrix: focal lengths and principal point. k[0] == 0 indicates uncalibrated data. |
r | Rectification rotation. |
p | Projection matrix for the rectified image; its intrinsics can differ from k. |
binning_x, binning_y, roi | Capture geometry that must be accounted for when interpreting pixels. |
These are the conventions in the official CameraInfo message definition. Capital K, D, R and P below denote the mathematical matrices; ROS 2 message fields use lower-case names.
For the simple, zero-distortion example below, projection is u = fx × X/Z + cx, v = fy × Y/Z + cy. Back-projection gives a ray unless you also know depth. Do not mix a raw detection with rectified intrinsics or apply distortion correction twice.
2. The Optical Frame Mystery: ROS Standard vs. Optical Standard
An image can look correct while the robot interprets a rightward object as upward or backward. Check the coordinate convention before recalibrating the lens.
Physical camera_link (Body Frame)
A body-oriented camera frame commonly uses X forward, Y left, Z up. Its origin and mounting transform come from the driver or robot model; the frame name alone does not establish a measured optical centre.
Logical camera_optical_frame (Sensor/Image Frame)
The optical convention is X right, Y down, Z forward. In the following example, camera_optical_frame is the frame of the projected 3D points. REP 103 defines these right-handed body and optical conventions.
The Discrepancy: Mapping Optical Axes to Body Axes
The complete optical-to-body conversion is given by the matrix below. State the source and target frames before applying it. For coincident origins and the stated axis conventions, converting optical coordinates to body coordinates gives:
1 | p_link = R_link_from_optical × p_optical |
A point straight ahead along optical Z therefore becomes a point along body X. A point to the image’s right has negative body Y. The reverse conversion uses the transpose of this rotation. A real mount adds its own rotation and translation; do not infer those from this example or publish a duplicate transform already owned by the camera driver.

Schematic: camera_link and camera_optical_frame use different axis conventions. The numeric mapping above states exactly which direction is being computed.
Undistortion and Re-projection Error: Making Pixels Tell the Truth
For a point with known 3D coordinates, project it through the chosen camera model and compare the predicted pixel with the observed pixel. Here the per-point reprojection RMS is:
1 | RMS_px = sqrt(sum((u_pred - u_obs)^2 + (v_pred - v_obs)^2) / N) |
N counts points, not scalar coordinates. A score calculated with a different denominator is not directly comparable. Inspect residuals across the image as well as the aggregate: a global shift suggests a different failure from errors that grow toward the edges.
On real data, check images beyond those used to fit the model. There is no universal acceptable pixel error independent of optics, image resolution and the downstream task. Nor does a low reprojection error prove that the camera-to-robot transform or timestamps are correct. In this article’s ideal fixture, zero error only means that known arithmetic agrees with known inputs.
3. Spatial Awareness: Linking Camera Vision to the Robot’s Body with TF2
Intrinsics relate points in the optical frame to pixels. Extrinsics relate coordinate frames to one another. Keep these questions separate when debugging: changing the mount transform cannot repair an incorrect focal length.
Extrinsic Calibration: Where is the Camera on the Robot?
The camera-to-robot transform must describe the actual mount. Mechanical measurements can provide an initial estimate. Target-based or hand-eye methods can estimate it from additional observations, but they require their own geometry and assumptions; the intrinsic checkerboard calibration does not automatically supply base_link extrinsics.
For a rigid camera mount, represent the fixed relationship in the robot model or an appropriate static transform publisher. A camera on a moving joint also needs the time-dependent chain through that joint. Assign one owner to each transform, as discussed in ROS 2 architecture patterns.
The Power of TF2: The Coordinate Frame Dictionary
TF2 lets a consumer request a transform from a source frame into a target frame at a specified time. The transform chain might be camera_optical_frame → camera_link → base_link; those names do not remove the need for correct measurements and timestamps.

Schematic: a TF2 tree connects the camera optical frame to the robot’s other frames.
Practical example with a measured 3D point
Suppose a perception component supplies a PointStamped in camera_optical_frame. Its metric depth might come from an appropriate depth measurement; a 2D detection alone cannot populate that point. Set the observation’s acquisition timestamp, then transform the point to base_link.
This integration fragment follows the Jazzy Buffer interface and geometry message registration. It assumes an existing buffer/listener receiving transforms; it was checked against source documentation and parsed locally, not executed in ROS:
1 | import tf2_geometry_msgs # Registers PointStamped transformations. |
Buffer.transform uses the stamped input’s frame and time. Catch TransformException in the caller and handle an unavailable transform explicitly; for example, reject or defer the observation under a bounded policy. A zero timeout avoids waiting inside this fragment. Do not silently substitute the latest transform for an older measurement on a moving robot. The output is a coordinate conversion, not an authorized or collision-checked motion command.
If transforms are plausible but observations still appear stale, check ROS 2 clock domains and sensor timestamps before revisiting calibration.
A reproducible CameraInfo-to-base example
The downloadable example isolates projection and frame arithmetic from ROS installation and camera hardware. It uses six synthetic correspondences, predetermined intrinsics and a predetermined mount. It does not estimate calibration parameters, detect checkerboards or rectify images.
Save these five files in the same directory: Python checker, camera and mount fixture, six correspondences, expected JSON output, and README with limits.
The same original files are available in the versioned source repository, with reuse terms and the exact release history.
Run with Python 3.9 or later; no third-party packages are needed:
1 | python3 camera_geometry_check.py --self-test |
The JSON fixture is a teaching subset of CameraInfo, not a file to install into a camera driver. It defines a 640 × 480 monocular image, fx = fy = 500 px, cx = 320 px, cy = 240 px, zero distortion, identity rectification and P = [K | 0]. There is no binning, crop or stereo baseline. These assumptions make raw and rectified projection coincide only in this example.
The mount is also explicit: camera_link has axes parallel to base_link, and its origin is (0.2, 0, 0.5) m in base_link. Both camera frames share that origin. Therefore:
1 | p_base = R_base_from_optical × p_optical + (0.2, 0, 0.5) |
| Synthetic point in optical coordinates, metres | Predicted pixel (u, v) | Expected point in base_link, metres |
|---|---|---|
(0, 0, 2) | (320, 240) | (2.2, 0, 0.5) |
(0.2, 0, 2) | (370, 240) | (2.2, -0.2, 0.5) |
(0, 0.1, 2) | (320, 265) | (2.2, 0, 0.4) |
(-0.3, -0.15, 1.5) | (220, 190) | (1.7, 0.3, 0.65) |
(0.1, -0.05, 1) | (370, 215) | (1.2, -0.1, 0.55) |
(-0.4, 0.2, 4) | (270, 265) | (4.2, 0.4, 0.3) |
The replay produces 0 px reprojection RMS and 0 m maximum base-coordinate error against these supplied answers, with a comparison tolerance of 1e-9. Deliberately adding 5 px to cx in both K and P produces 5 px RMS while leaving the base-coordinate transform unchanged. That contrast helps separate an intrinsic projection mismatch from a frame mismatch; it is not a measured camera benchmark.
The ten tests also check axis directions, inverse transforms, known-depth back-projection and rejection of unsupported or nonfinite inputs. For example, pixel (370, 265) corresponds to (0.2, 0.1, 2) m when optical-Z depth is 2 m, but (0.4, 0.2, 4) m at depth 4 m. Both lie on the same ray. Optical-Z depth is not the same quantity as Euclidean range from the camera.
Diagnose the symptom before changing calibration
| Symptom | First check | What the synthetic example can establish |
|---|---|---|
| Point appears on the wrong side of the robot | Frame IDs, transform direction and axis conventions | Known optical-to-base axis mapping and inverse |
| Pixels are shifted despite plausible 3D coordinates | Matching image mode, principal point, raw versus rectified model | The controlled cx + 5 px residual |
| CameraInfo is present but image remains distorted | Whether rectification actually runs; image topic and distortion model | Nothing about real distortion: the fixture assumes D=0 |
| Detection moves incorrectly while robot moves | Acquisition time, TF availability and clock domains | Nothing about runtime timing: ROS is not running here |
| Pixel is known but metric point is unknown | Available depth or geometric constraint | Multiple depths produce the same pixel |
Conclusion: From Pixels to Precision
A dependable camera pipeline has distinct checks: acquire calibration observations, verify the image metadata, use the correct projection model, and transform measured points through a time-consistent frame chain. Start with the downloadable fixture to verify signs and units, then repeat the relevant checks with your own camera data and recorded transforms.
For the surrounding ROS 2 component model, keep image acquisition, perception and transform ownership explicit. When combining camera estimates with other sensors, the sensor-fusion worked example explains why coordinate agreement still leaves timing and uncertainty to validate.
