Camera calibration

Camera calibration recovers the intrinsic matrix K\mathbf{K} and the lens distortion parameters of a camera from images of a known calibration target. Without accurate calibration, every downstream geometric computation — triangulation, pose estimation, epipolar search — is systematically wrong.

Zhang’s Method

Zhang’s method (1999) is the standard calibration procedure. It uses images of a planar checkerboard taken from multiple viewpoints. Each image provides correspondences between known 3D board corners and detected 2D image corners, giving constraints on both the homography (image-to-board) and the intrinsic parameters. The procedure:

  1. Detect checkerboard corners in N3N \geq 3 images at different orientations.
  2. Compute homographies HiH_i between the board plane and each image.
  3. Extract constraints on K\mathbf{K} from each HiH_i, using H=λK[r1,r2,t]H = \lambda\mathbf{K}[r_1, r_2, \mathbf{t}] with r1r2r_1 \perp r_2 and r1=r2\|r_1\| = \|r_2\|.
  4. Solve a linear system for the intrinsic parameters.
  5. Refine all parameters (intrinsic + extrinsic + distortion) via nonlinear least squares.

Where the constraints come from. Write H=[h1,h2,h3]H = [\mathbf{h}_1, \mathbf{h}_2, \mathbf{h}_3]. Since h1Kr1\mathbf{h}_1 \propto \mathbf{K}r_1 and h2Kr2\mathbf{h}_2 \propto \mathbf{K}r_2 with r1,r2r_1, r_2 orthonormal, each view yields two linear equations in the entries of the symmetric matrix B=KTK1B = \mathbf{K}^{-T}\mathbf{K}^{-1}:

h1TBh2=0,h1TBh1=h2TBh2\mathbf{h}_1^T B\, \mathbf{h}_2 = 0, \qquad \mathbf{h}_1^T B\, \mathbf{h}_1 = \mathbf{h}_2^T B\, \mathbf{h}_2

BB has 6 unknowns (5 if skew is assumed zero), so 3 views suffice; K\mathbf{K} is then recovered from BB by Cholesky-style decomposition. This is why the board must be shown at different orientations — parallel views give redundant constraints.

Lens Distortion Models

Real lenses deviate from the ideal pinhole model. Two standard models:

Radial distortion causes straight lines to appear curved:

xd=x(1+k1r2+k2r4+k3r6),yd=y(1+k1r2+k2r4+k3r6)x_d = x'(1 + k_1 r^2 + k_2 r^4 + k_3 r^6), \qquad y_d = y'(1 + k_1 r^2 + k_2 r^4 + k_3 r^6)

where r2=x2+y2r^2 = x'^2 + y'^2 is the squared distance from the principal point. k1>0k_1 > 0 gives barrel distortion; k1<0k_1 < 0 gives pincushion distortion. Wide-angle lenses have large k1|k_1|.

Tangential distortion is caused by the lens not being perfectly parallel to the image plane:

xd=x+2p1xy+p2(r2+2x2),yd=y+p1(r2+2y2)+2p2xyx_d = x' + 2p_1 x'y' + p_2(r^2 + 2x'^2), \qquad y_d = y' + p_1(r^2 + 2y'^2) + 2p_2 x'y'

In practice, k1,k2k_1, k_2 (and sometimes k3,p1,p2k_3, p_1, p_2) are estimated jointly with K\mathbf{K}. OpenCV implements this directly in cv::calibrateCamera().

Judging calibration quality

The standard quality metric is the RMS reprojection error returned by the calibration: reproject the board corners with the estimated parameters and measure the pixel residuals. Beyond the single number, check that:

Common pitfalls

Why it matters for SLAM

SLAM systems assume that undistorted, calibrated observations feed their geometric solvers; a few pixels of uncorrected distortion at the image border can dominate reprojection error and corrupt the map. Calibration is also the template for harder problems you will meet later — camera-IMU and camera-LiDAR extrinsic calibration follow the same “known target + nonlinear refinement” pattern. Practically, calibrating your own camera with a checkerboard is one of the best first exercises in the field.