Calibr
Back to blog

What Is Camera Calibration? A Scientific Introduction

A first-principles tour of the pinhole model, distortion, the calibration problem, and reprojection error — with the math, the diagrams, and the references behind each step.

Key takeaways

What you will learn

  • Camera calibration estimates the parameters that map a 3D world point to its 2D image pixel.
  • The intrinsic matrix K describes focal lengths and principal point; the distortion vector D describes how lenses deviate from an ideal pinhole.
  • Calibration is a nonlinear least-squares problem: given known 3D–2D correspondences, find K and D that minimise reprojection error.
  • RMS reprojection error is the standard quality metric, but per-frame and per-region diagnostics matter more than a single number.
  • OpenCV’s calibrateCamera is built on Zhengyou Zhang’s 2000 paper, which made the problem tractable for any flat target.
01

The mapping from world to pixel

A camera does not record pixels — it records light. Every pixel value in an image is the result of light reflecting off some 3D surface in the world, passing through a lens, and being measured by a sensor element. Camera calibration is the inverse problem: given the pixels, can we describe the geometric function f:R3R2f : \mathbb{R}^3 \to \mathbb{R}^2 that produced them?

The key to understanding that function is realizing it is not one transformation but a chain of four, passing through four different coordinate systems — each with its own origin. A point travels from the world frame, into the camera frame, onto the image plane, and finally into pixel coordinates. Throughout this article we use a strict convention: capital letters denote the axes of a coordinate system (XWX_W, YWY_W, ZWZ_W), while lowercase letters denote the coordinates of a specific point measured along those axes (xwx_w, ywy_w, zwz_w).

Step 1: the world frame. The world coordinate system is arbitrary — we choose it. In calibration it is typically anchored to the target: the origin OWO_W sits at a corner of the checkerboard, with XWX_W and YWY_W spanning the board plane and ZWZ_W perpendicular to it. A point PP in the scene has world coordinates (xw,yw,zw)(x_w, y_w, z_w); for a point on the board itself, zw=0z_w = 0. Nothing about the camera has entered the picture yet — this frame describes the scene, not the sensor.

A checkerboard target centered in the world coordinate frame with the world origin and a point P on the board
The world frame is chosen by convention: here the checkerboard corner is the origin, the board spans the world X and Y axes, and a target point P is measured as world coordinates.

Step 2: the extrinsic transform. The camera has its own coordinate system: its origin is the optical center CC (the point all rays pass through), with XCX_C pointing right, YCY_C pointing down, and ZCZ_C pointing forward along the optical axis into the scene. The extrinsic parameters — a rotation RR and a translation t\mathbf{t} — re-express the point in this frame: [xcyczc]=R[xwywzw]+t\begin{bmatrix} x_c \\ y_c \\ z_c \end{bmatrix} = R \begin{bmatrix} x_w \\ y_w \\ z_w \end{bmatrix} + \mathbf{t} It is worth pausing on what this does and does not do. The point PP has not moved. Only the reference frame has changed: the same physical point now carries new coordinates (xc,yc,zc)(x_c, y_c, z_c) — its position as seen from the camera. In particular, zcz_c is the point's depth along the camera's viewing direction, a quantity that simply does not exist in the world frame.

Two properties of the extrinsics deserve precision, because they are the source of endless bugs. First, RR is not nine free numbers: it is an orthonormal rotation matrix (RR=IR^\top R = I, detR=+1\det R = +1) with only three degrees of freedom, which is why libraries store it compactly as an axis–angle vector (OpenCV's rvec, expanded via the Rodrigues formula). Second — and this is the classic trap — t\mathbf{t} is not the camera's position in the world. Setting (xw,yw,zw)=(0,0,0)(x_w, y_w, z_w) = (0,0,0) in the equation above shows that t\mathbf{t} is the world origin expressed in the camera frame. The camera's actual position in world coordinates is C=RtC = -R^\top \mathbf{t}. Report tvec as "camera position" and every downstream measurement will be silently wrong.

The checkerboard world frame and the camera frame connected by the extrinsic rotation and translation
Extrinsics are a change of coordinates: R rotates the world frame into the camera frame, while t is the world origin expressed from the camera, not the camera position itself.

Step 3: the perspective divide. This is the step where a photograph actually happens. An ideal pinhole projects the point onto a plane at unit distance in front of CC by dividing out the depth: xn=xczc,yn=yczcx_n = \frac{x_c}{z_c}, \qquad y_n = \frac{y_c}{z_c} These normalized image coordinates are dimensionless and independent of any particular sensor. The divide is the only nonlinear operation in the entire chain, and it is where information is destroyed: 3D collapses to 2D, depth is gone, and "farther away" becomes "smaller" as a direct consequence of the arithmetic. It is also why a single pixel can never be inverted back to a 3D point — only to a ray of candidate points through CC, all of which share the same (xn,yn)(x_n, y_n).

Side-view projection geometry showing similar triangles for the perspective divide
The perspective divide is just similar triangles: the same angle gives tan(theta) = coordinate/depth = image-plane displacement/focal length, so U and V scale with f and shrink with depth.

Step 4: the intrinsic matrix. So far no property of the physical camera has appeared — the normalized coordinates would be identical for any ideal pinhole. The intrinsics convert this idealized description into the actual pixel grid of a specific sensor: u=fxxn+cx,v=fyyn+cyu = f_x\, x_n + c_x, \qquad v = f_y\, y_n + c_y Here fxf_x and fyf_y are the focal lengths expressed in pixels — the lens focal length multiplied by the sensor's pixel density — which is why a "35 mm" lens produces fxf_x values in the thousands. They control how many pixels one unit of normalized coordinate spans: the magnification. The principal point (cx,cy)(c_x, c_y) handles a bookkeeping fact: the projection is naturally centered on the optical axis, but images are indexed from the top-left corner. The offset (cx,cy)(c_x, c_y) is the pixel location where the optical axis pierces the sensor — near the image center, but never exactly, which is why it is estimated rather than assumed. Packed as a matrix, with a skew term ss that is effectively zero on modern sensors: K=[fxscx0fycy001]K = \begin{bmatrix} f_x & s & c_x \\ 0 & f_y & c_y \\ 0 & 0 & 1 \end{bmatrix}

Sensor pixel grid showing focal length scaling and principal point offsets
The intrinsic step turns normalized coordinates into pixels: focal length controls scale, while the principal point shifts the optical-axis origin into the image coordinate system.
Animated explanation of fx, fy, cx, and cy moving points on the pixel grid
Animated view of the intrinsic parameters: fx and fy scale normalized coordinates, while cx and cy translate them to the pixel grid origin.

Chaining all four steps in homogeneous coordinates gives the full ideal pinhole model in a single line: zc[uv1]=K[Rt][xwywzw1]z_c \begin{bmatrix} u \\ v \\ 1 \end{bmatrix} = K\, [\, R \mid \mathbf{t}\, ] \begin{bmatrix} x_w \\ y_w \\ z_w \\ 1 \end{bmatrix} Note the zcz_c on the left-hand side: that is the perspective divide from step three, hiding in plain sight. One computes the right-hand side and divides by the third component to obtain the pixel (u,v)(u, v). Counting parameters, the model has 11 degrees of freedom — 5 intrinsic (fx,fy,cx,cy,sf_x, f_y, c_x, c_y, s) and 6 extrinsic (3 for RR, 3 for t\mathbf{t}).

One deliberate omission: real lenses are not ideal pinholes. Between the perspective divide and the intrinsic matrix, the lens bends the normalized coordinates — radial and tangential distortion — and this bending is nonlinear, so it cannot be absorbed into KK. We treat it in detail in a later section; for the structure of the mapping, the ideal model above is the skeleton everything else hangs on.

Calibration, then, is the estimation problem this chain defines: recover the intrinsic parameters (and distortion coefficients) that are fixed properties of the camera, and — usually as a byproduct — the per-image extrinsics [Rt][R \mid \mathbf{t}] describing where the camera stood for each frame used in the solve. Once the intrinsics are known, the chain can be run in both directions: undistorting images, projecting world points to pixels, triangulating from stereo pairs, and estimating pose from known features. None of those are possible without first answering: what camera am I dealing with?

The same 3D point P shown in both the world frame and the camera frame, related by the extrinsic transform [R | t], with the ray from P through the optical centre C crossing the image plane at pixel (u, v)
One point, two frames, one image: a world point P is re-expressed in the camera frame by the extrinsics [R | t], then projected along the ray through the optical centre C to the pixel (u, v).
02

The pinhole model

The simplest geometric model of a camera is the pinhole: imagine all light passing through a single infinitesimal aperture at the camera centre OO, then landing on a planar sensor at distance ff (the focal length) behind it. Using the virtual-image convention, where the sensor sits between OO and the world, similar triangles give the projection equations x=fXZ,y=fYZx' = f \cdot \frac{X}{Z}, \qquad y' = f \cdot \frac{Y}{Z}

Written in homogeneous coordinates and rolled together with the extrinsics, this gives the standard pinhole equation x=K[Rt]X\mathbf{x} = K \, [\, R \mid \mathbf{t} \,] \, \mathbf{X} where X=(X,Y,Z,1)\mathbf{X} = (X, Y, Z, 1)^\top is a homogeneous world point and x=(u,v,1)\mathbf{x} = (u, v, 1)^\top is its homogeneous pixel coordinate. The 3×33 \times 3 intrinsic matrix KK does the work of converting metric image-plane coordinates into pixel coordinates.

In pixels rather than metres, the focal length splits into fxf_x and fyf_y (the metric focal length divided by the horizontal and vertical pixel pitch). The principal point (cx,cy)(c_x, c_y) is where the optical axis pierces the sensor — close to but rarely exactly at the image centre. Together, fx,fy,cx,cyf_x, f_y, c_x, c_y are the four intrinsic parameters of an ideal pinhole camera.

The intrinsic camera matrix K with focal lengths fx, fy and principal point cx, cy highlighted
The intrinsic matrix K encodes how the lens focuses light onto pixel coordinates. Real cameras almost always have fx ≈ fy and cx, cy near the image centre — but rarely exactly.
03

Why distortion exists

A real lens is not an infinitesimal pinhole. It is a stack of curved glass elements designed to gather more light and project a sharp image. That design introduces deviations from the pure pinhole projection — most prominently, radial distortion, where points appear shifted along the radial direction from the optical centre. Wide-angle and fisheye lenses bow lines outward (barrel distortion), while telephoto lenses can bow them inward (pincushion).

Lens distortion diagram showing how curved glass bends projected rays away from the ideal pinhole model
Real lenses bend rays before they reach the sensor, so the measured point is displaced from the ideal pinhole projection.
Animated comparison of barrel and pincushion lens distortion on a grid
Barrel and pincushion distortion move pixels radially around the optical centre, bending straight grid lines in opposite directions.

OpenCV models radial distortion with a polynomial in the radial distance rr from the principal point: rd=r(1+k1r2+k2r4+k3r6)r_d = r \cdot \bigl(1 + k_1 r^2 + k_2 r^4 + k_3 r^6\bigr) Most reasonable lenses are captured by k1k_1 and k2k_2; k3k_3 is added for wide-angle. The rational model extends this with k4,k5,k6k_4, k_5, k_6 in a denominator polynomial for cameras with stronger distortion. Fisheye lenses use a different model entirely — the equidistant projection — because the polynomial approach breaks down near 180°.

There is also tangential distortion, parameterised by p1p_1 and p2p_2, which appears when the lens elements are not perfectly parallel to the sensor. It is usually small for modern cameras but matters for high-precision work. The full distortion vector D=(k1,k2,p1,p2,k3)D = (k_1, k_2, p_1, p_2, k_3) is what calibration estimates alongside KK.

Three grids showing barrel distortion, ideal undistorted grid, and pincushion distortion
Radial distortion shows up as systematic curvature of straight world lines. Calibration recovers the coefficients that map distorted pixels back to ideal pinhole pixels.
04

The calibration problem, stated formally

Calibration is an optimisation. We capture NN images of a planar target whose 3D coordinates Xj\mathbf{X}_j are known by construction (a chessboard, ChArUco board, or circles grid). In each image ii we detect the projections xij\mathbf{x}_{ij} of those known points. The unknowns are: the intrinsics KK and distortion DD (shared across all images), and a per-image rigid pose (Ri,ti)(R_i, \mathbf{t}_i).

The goal is to find the parameters that make the predicted projections π(K,D,Ri,ti,Xj)\pi(K, D, R_i, \mathbf{t}_i, \mathbf{X}_j) match the observations xij\mathbf{x}_{ij} as closely as possible, in the sense of squared pixel distance. Concretely: minK,D,{Ri,ti}    i,jxijπ(K,D,Ri,ti,Xj)2\min_{K, D, \{R_i, \mathbf{t}_i\}} \;\; \sum_{i, j} \bigl\lVert \mathbf{x}_{ij} - \pi(K, D, R_i, \mathbf{t}_i, \mathbf{X}_j) \bigr\rVert^2

This is a nonlinear least-squares problem because π\pi is nonlinear in the unknowns (the distortion polynomial is the obvious source of nonlinearity, but rotation is also). The standard solver is Levenberg–Marquardt, initialised from a closed-form solution that ignores distortion. The closed-form initialisation is Zhang's contribution from his 2000 paper: he showed that the homographies between a planar target and its images give linear constraints on KK, after which distortion can be added back and the whole thing refined nonlinearly.

Calibration target with detected corners and reprojected predicted corners, with residual vectors between them
Calibration minimises the sum of squared residuals between detected corners (dark green) and the corners predicted by the model (light green).
05

Reading reprojection error

The standard quality metric is the root mean square reprojection error: erms=1Nixiπ(θ,Xi)2e_{\text{rms}} = \sqrt{\, \frac{1}{N} \sum_{i} \bigl\lVert \mathbf{x}_i - \pi(\boldsymbol\theta, \mathbf{X}_i) \bigr\rVert^2 \,} where NN is the total number of point observations and θ\boldsymbol\theta is the full parameter vector. This is the same quantity the optimiser was minimising, evaluated at the converged solution. It has units of pixels.

What counts as "low"? It depends on the application. For typical machine-vision lenses on a moderate-resolution sensor, an RMS below 0.5px0.5\,\text{px} is excellent, 0.50.51.0px1.0\,\text{px} is good, and above 2px2\,\text{px} usually means weak frames, wrong board parameters, or a model mismatch (e.g. trying to fit a fisheye lens with a pinhole model). For sub-pixel measurement work in metrology, sub-0.2px0.2\,\text{px} is the target.

The trap is that one number can hide a lot. A run can show a respectable average while one or two outlier frames carry most of the error, or while the error is concentrated near the edges of the sensor where the distortion model is failing. That is why analytics that show per-image error, sensor coverage, and residual heatmaps are essential — and why CalibrX surfaces all three.

06

Three camera models, three trade-offs

In practice, "the pinhole model" is one of several models. Choosing the right one matters: a wide-angle lens fit with a strict pinhole will end up with a high RMS and ugly undistortion at the edges, while a normal lens fit as fisheye will produce parameters with strange physical meaning.

The three families most commonly used: the standard pinhole (Brown-Conrady distortion, OpenCV’s calibrateCamera) for moderate lenses up to roughly 90° field of view; the rational pinhole (additional k₄, k₅, k₆ in a denominator polynomial) for wide-angle lenses up to about 120°; and the equidistant fisheye model (Kannala–Brandt or OpenCV’s fisheye namespace) for true fisheye projections approaching 180°. CalibrX surfaces all three so you can solve the same captures against each and compare RMS and undistorted previews directly.

  • Pinhole — standard rectilinear lenses, 4 to 8 distortion coefficients.
  • Pinhole wide — rational distortion model for wide-angle and action cameras.
  • Fisheye — equidistant projection (Kannala–Brandt) for dome and 180° lenses.
07

What the parameters let you do

Once calibration has converged, K and D are the keys to every geometric operation the camera can support. Undistorting an image becomes a function call that takes pixels in and pixels out with straight lines preserved. Projecting a 3D world point becomes deterministic. Triangulating depth from a stereo pair requires both cameras’ intrinsics and the rectification homography that aligns their epipolar lines.

For applications that consume the calibration — robotics, drones, AR, 3D reconstruction, machine vision — the export needs more than the raw numbers. It needs the model identifier (pinhole, pinhole_wide, fisheye), the image size used during solving, and ideally the RMS and per-image quality metadata. That structured export is what CalibrX writes to JSON or YAML, and what the calibrx Python SDK reads back to drive undistortion locally with the correct model-specific routine.

Further reading

  1. Zhang, Z. — A Flexible New Technique for Camera Calibration (2000)The paper that made planar-target calibration practical for any flat board. Underpins OpenCV’s calibrateCamera.
  2. OpenCV — Camera calibration with OpenCVThe official tutorial covering K, D, the calibration pipeline, and undistortion in OpenCV.
  3. OpenCV calib3d module referenceAPI reference for calibrateCamera, undistort, projectPoints, and the rational distortion model.
  4. Kannala & Brandt — A Generic Camera Model and Calibration Method (2006)The equidistant fisheye model used by OpenCV’s cv2.fisheye namespace for wide and 180° lenses.
  5. Hartley & Zisserman — Multiple View Geometry in Computer VisionThe canonical textbook on projective geometry, camera models, calibration, and multi-view reconstruction.
  6. CalibrX — camera calibration softwareRun the pinhole, wide, and fisheye calibration described here in the browser: upload images, detect patterns, validate accuracy, and export calibration files.