Atlas Robotics
CameraIntermediate

Camera calibration: why images need to be corrected

Atlasbot · 18/8/2026 · 11 min read

Camera calibration: why images need to be corrected
Camera calibration using checkerboard to find lens distortion parameters

Lens shots are never completely "straight" — straight lines in real-world can be slightly curved on the image, especially at wide - angle cameras. For applications that only need object recognition, this minor deviation is usually negligible. But when it is necessary to measure the true distance or size from the image (stereo vision, AR marker, camera SLAM), this bias must be corrected — which is the aim of Camera Calibration.

Key concepts

The calibration process calculates two parameter groups:

  • The intrinsic matrix — the focal length and the optical center of the lens itself, which are specific to each camera
  • distortion coefficients — describe the lens-induced curvature (the barrel/block-shape distortion common in wide-angle cameras), used to "shape" images to the correct geometry

With this parameter, software can switch back and forth between pixel coordinates on images and real coordinates in space — mandatory platforms for stereo vision (depth estimates from 2 cameras, learned similarly in Camera in AMR) or camera - based SLAM algorithms.

How it works

The most common way is to print a checkerboard of a known square size, capture it from different angles, and then let the tool calculate the parameters themselves based on the checkerboard angles detected on each image.

ros2 run camera_calibration cameracalibrator \
  --size 8x6 --square 0.024 \
  --ros-args -r image:=/camera/image_raw

--size 8x6 is the number of interior angles (not squares) in the horizontal × vertical of the board; --square 0.024 is the edge size of each square in meters, which must be accurately measured with a ruler. The tool will ask to move the board through various positions/tips in the frame until there is enough data, then output a YAML file containing the intrinsic matrix and coefficient distortion — which is reloaded each time the camera node is started to automatically fine tune the image.

Technical details

Formulas

The intrinsic matrix takes the standard form, the focal length in pixels directly related to the physical focal length and the sensor size:

Intrinsic matrix K:
| fx  0   cx |
| 0   fy  cy |
| 0   0   1  |

fx, fy = focal lengths along x, y (pixels)
cx, cy = optical center coordinates (usually near the image center)

Relating focal length in pixels to physical focal length:
fx (pixels) = f (mm) × (Image_width_pixels / Sensor_width_mm)

Example: physical focal length 4mm, sensor width 5mm, image width 640 pixels
fx ≈ 4 × (640/5) = 512 pixels

The conversion from pixel coordinates to real-world coordinates (used for stereo vision, learned the formula Z = f×B/d in Camera in AMR) is all based on these fx, fy, cx, cy parameters.

Parameters

SituationNeed calibration?
Object detection/tracking onlyNot required
Stereo camera calculation of depthRequired
AR marker localizationRequired
Visual SLAMRequired

Practical applications

If you're just using a camera for object detection or tracking without measuring the exact distance/size, skip this step. Calibration is necessary when: using stereo camera to calculate depth (directly applying the formula Z = f×B/d learned in Camera in AMR, where f is the pixel focal length from calibration), using AR markers for localization, or running visual SLAM.

Practical example

import numpy as np
import cv2

# After calibration, load the YAML parameter file
camera_matrix = np.array([[512.0, 0, 320.0],
                            [0, 512.0, 240.0],
                            [0, 0, 1]])
dist_coeffs = np.array([0.05, -0.1, 0, 0, 0])  # distortion parameters (example)

frame = cv2.imread("raw_frame.jpg")
undistorted = cv2.undistort(frame, camera_matrix, dist_coeffs)

cv2.imwrite("undistorted_frame.jpg", undistorted)
print("Da nan anh, luu ket qua")
Before calibration (raw_frame.jpg): actual straight lines (such as door edges
or straight shelves) appear slightly curved near the image edges

After calibration (undistorted_frame.jpg): lines remain straight
across the entire frame, ready for accurate distance measurements

Common mistakes

  • Submitting calibration when implementing stereo vision or visual SLAM— as the Parameter table, this is a mandatory step, lacking it causing all distance/size measurements to systematically deviate.
  • Miscalculating checkerboard square size when calibrating— wrong parameter --square directly falsifies the entire computed intrinsic matrix, affecting the chain to all subsequent measurements.
  • Prisoning the board from only a single angle/distance — does not have sufficient data diversity to accurately estimate the distortion coefficient, especially in the frame edge region where distortion is most pronounced.
  • Recalibration per boot rather than saving and reusing — calibration is a one-time preprocessing step for each camera (unless a physical zoom/focus is changed), without the need to repeat each session.

Conclusion

Camera Calibration is a one - time preparation step for each camera, which does not have to be redone every — run but is required if the application needs to infer real distance or size from the image, rather than just identifying "something in the frame". The focal length parameter derived from the calibration is the direct input to the stereo vision formula learned in Camera in AMR. This is the last of a two-part unit on Camera — the next IMU unit to go into inertial sensing, another sensor piece of AMR.

Get new articles and lessons by email

When a new technical article or course module is published, Atlas Robotics sends you a short email. No spam.

Unsubscribe any time with the link in each email. See our Privacy policy.

Camera calibration: why images need to be corrected — Atlas Robotics