Calibration with a known target
A pinhole camera maps a world point to a pixel with one 3 × 4 matrix:
The target here is the classic calibration rig: two perpendicular checkerboards, 5 cm squares, in the planes and of a world frame with up. Its inner corners have known coordinates , and their pixels are measured in the image, here with Gaussian noise of pixels.
Two equations per point
Dividing by gives the pixel, and multiplying the denominator out gives equations linear in :
and likewise for . has 12 entries, but like every projective matrix it is only defined up to scale, which leaves 11 unknowns. Each point gives two equations, so 5.5 points determine : at least 6 are needed. More points make the system overdetermined, and least squares finds the that fits them best, which makes the result robust to errors in the measured corners.
Method 1:
Fix the scale by setting . The terms with move to the right-hand side, and the system has 11 unknowns:
is , and the least-squares solution is , as for vertical least squares. The catch is : it equals , the depth of the world origin in front of the camera. If the world origin lies near the plane through the camera center parallel to the image, , and forcing it to 1 needs an enormous scale for all other entries. Here the origin, the inner corner of the rig, is well in front of the camera.
Method 2:
Keep all 12 entries, with the last column , , and look for the unit vector that makes smallest: the right singular vector of the smallest singular value of the matrix , the last column of in the SVD, as in total least squares and for a homography. Without noise, ; with noise it measures how well the points agree with a single .
The target must not be flat. All points of one plane satisfy a linear equation, so adding any multiple of that equation to a row of changes nothing for them: three extra directions besides the scale. Four singular values drop to zero, and the solution is an arbitrary vector of this four-dimensional null space rather than . For the board in the plane , the columns of , and are all zero, and a vector with only satisfies every equation as , while sending every point to . That is why the rig has two boards.
Factorizing back into
The left 3 × 3 block of is : an upper triangular matrix times a rotation. The RQ decomposition splits a matrix exactly into these two factors: the upper triangular one is , the orthogonal one is . Here it is computed with three Givens rotations that zero the entries below the diagonal. The decomposition leaves signs open, so it needs post-processing to give valid matrices: the diagonal of is made positive, is negated if comes out as a reflection (the SVD can return just as well as ), and is scaled to . The last column of is , so
Recovering the camera center
The camera center is not : the point is rotated before the translation is added. The center is the point that maps to 0, , so
which needs neither the RQ decomposition nor the scale of .
Linear calibration and beyond
The linear method is easy to set up and solve, and it needs no initial guess. But it only gives , and the camera parameters have to be extracted from it. It does not model radial lens distortion, and it cannot impose constraints such as zero skew or square pixels: comes out as whatever fits the noise best. It also minimizes an algebraic error , not the distance in pixels. In practice the linear result is the starting point for a non-linear method, which defines the error as the difference between the projected and the measured points and minimizes it with Newton's method or a similar optimizer.
Try this
- Set the noise to 0: , , and equal the true values, the reprojection error is 0, and the last singular value drops to about .
- Still without noise, reduce the points to 6: the result stays exact, since 6 points give 12 equations for 11 unknowns. Now add 0.5 px of noise and press New noise a few times: and jump by tens of pixels and centimeters. Increase the number of points and they settle down.
- Look at where lands in the 3D view: with noise it moves mostly along the viewing direction, and , change with it. A camera a bit closer with a slightly wider view sees almost the same image.
- Increase the distance to 3 m with 1 px of noise: the rig covers only a small part of the image, and the estimates of , and fall apart, even though the reprojection error stays small.
- Turn on one plane only: with , four singular values drop to (almost) zero, three of them exactly. has a single nonzero entry , the panel reports that is singular, and no reprojections are drawn. With , is singular and there is no solution at all.
- Set a skew : the RQ decomposition recovers it. Then set and add 2 px of noise: is no longer 0, because the linear method cannot enforce it.
- Switch between Method 1 and Method 2 with noise: the two estimates are close but not identical, because they minimize different algebraic errors.