Skip to content
AI360Xpert
Beta

Camera Calibration with a Checkerboard

Calibration shows the camera a checkerboard of known size from many angles and solves for the numbers that explain every corner. The verdict is one score: mean reprojection error in pixels.

Calibration solves for K, R, t and distortion together; mean reprojection error in pixels is the verdict
Calibration solves for K, R, t and distortion together; mean reprojection error in pixels is the verdict

Why Does This Exist?

Factory specs never describe your exact camera: the lens seated a fraction of a millimetre off, the sensor a touch rotated, the focus ring somewhere unknown. Intrinsic parameters, extrinsic parameters, and lens distortion say what the numbers mean; calibration is how you get them for the camera in your hand. Without it, stereo vision cannot rectify and structure from motion starts from fiction.

Think of It Like This

An eye exam with a known chart

The optometrist shows you a chart of known letters and flips lenses until you read the bottom row. The chart is the checkerboard: every square size known in advance. Each lens flip is a guess at your parameters. Your reading errors are reprojection errors, and the final prescription is the parameter set with the smallest total misread.

The analogy stops at reuse: glasses are fitted per person and stay valid, while calibration dies the moment focus, zoom, or the lens mount changes.

How It Actually Works

Print a checkerboard with known square size, photograph it from 1010 to 2020 varied poses, and detect its inner corners in each shot. Because the board is flat (Z=0Z = 0 in its own frame) each view gives a homography from board to image, and stacking those homographies yields a closed-form first guess at KK (Zhang's method). A nonlinear refinement then adjusts KK, every view's RR and tt, and the distortion coefficients together to minimize the reprojection error: for corner ii, with observed pixel oio_i and projected pixel pip_i, minimize the mean of ∥oi−pi∥\lVert o_i - p_i \rVert over all corners and views.

Worked numbers

One corner is observed at (521.3,639.1)(521.3, 639.1) while the current parameters project it to (520,640)(520, 640). Its error is:

(521.3−520)2+(639.1−640)2=1.69+0.81=2.5≈1.58 px\sqrt{(521.3 - 520)^2 + (639.1 - 640)^2} = \sqrt{1.69 + 0.81} = \sqrt{2.5} \approx 1.58 \text{ px}

With four corners scoring 1.581.58, 0.900.90, 1.101.10, and 0.700.70 pixels, the mean reprojection error is (1.58+0.90+1.10+0.70)/4=1.07(1.58 + 0.90 + 1.10 + 0.70) / 4 = 1.07 pixels. Below about one pixel on a clean board, the calibration is solid; several pixels mean something below went wrong.

Code

import math

def reproj_error(obs: tuple[float, float], proj: tuple[float, float]) -> float:    return math.dist(obs, proj)  # Euclidean gap in pixels

print(round(reproj_error((521.3, 639.1), (520.0, 640.0)), 2))  # -> 1.58print(round(sum([1.58, 0.90, 1.10, 0.70]) / 4, 2))  # -> 1.07

Watch Out For

Calibrating with near-parallel board poses

If every shot holds the board flat facing the camera, the views differ only by translation and the focal length stays weakly constrained: many (fx,tilt)(f_x, \text{tilt}) pairs explain the same corners. The optimizer converges, the error looks fine, and fresh angles then misproject badly. Tilt the board steeply in several shots so perspective, not just position, varies.

A misprinted square size

The whole reconstruction inherits the board's stated square size as its unit of length. A printer that scales the page to 9797 percent makes every downstream measurement 33 percent short, with zero warning from the reprojection error, which is scale-free. Measure the printed squares with calipers and enter the true size before solving.

The Quick Version

  • Calibration photographs a known board from varied poses and solves KK, per-view RR and tt, and distortion jointly.
  • Zhang's method gives the closed-form starting guess from stacked homographies.
  • The refinement minimizes mean reprojection error, measured in pixels.
  • Near one pixel of mean error means success; several pixels mean a setup problem.
  • Steeply tilted board poses constrain the focal length; flat frontal ones do not.
  • The entered square size becomes the unit of every later measurement.