How a Camera Turns the World into Pixels

A camera is a 3 by 4 matrix. It sends each 3D point to a pixel and throws the depth away. Photograph a flat checkerboard from two or more angles, and you can recover the camera's hidden numbers.

Choose how many photos of the board to take. Watch the recovered focal lengths and image centre close in on the truth. Then we build, piece by piece, the pinhole, the matrix K, the pose, lens distortion, calibration and the ray back out.

You need a matrix times a vector and a little Python. We build the rest from zero.

Lesson 8 of 15 in our follow-along of Stanford AA 274A, Principles of Robot Autonomy I. Every idea is re-taught here in our own words and devices. Before: Lesson 7, Sensors. Next: Lesson 9, Features and SfM.

Calibrate a camera from photos of a board

Photos of the board

0.5 px

Illustrative synthetic camera: fx 520, fy 500, cx 330, cy 235 px, no skew, a 640 by 480 image. The board has 9 by 6 corners, 30 mm apart. The solver is Zhang's method from Chapter 7, with zero skew assumed.

Chapter 0

A Camera Throws Away Depth

Slide two points along one line of sight and watch them land on the same pixel

Hold up your thumb at arm's length. Now bring it close to your eye. It can cover the same patch of view both times. A photo of it cannot tell you which.

A camera records the direction to each point, not its distance. Every point on one line from the lens out to infinity lands on the same pixel. That line is a ray. The depth along it is gone.

Slide two points along one ray

The near and far points sit on one ray through the pinhole. Slide each one. Watch where each lands on the image plane.

3.0 m
11.0 m

Illustrative toy: focal length 500 px, ray slope 0.3 (the point rises 0.3 m for each metre of depth).

Work the number. A soda can 0.12 m tall stands 0.4 m away. A billboard 9 m tall stands 30 m away. Both have height over depth 0.3. With a focal length of 500 px, each is 500 × 0.3 = 150 px tall in the image.

A robot needs both directions of this map. Forward: where does a 3D point land in the image? Backward: what does a pixel say about the world? This lesson builds both, then measures the camera's own numbers by calibration.

The failure, as symptom, measurement and fix

The symptom is a one-camera robot that misjudges range: late for a big object far away, early for a small one close by. To measure it, compare its range guess with a LiDAR or a tape. The fix is extra information: a second view, motion or a known size (Chapter 8).

The road

  1. The pinhole: similar triangles give x = f × X / Z.
  2. Pixels and K: five numbers turn a direction into a pixel.
  3. The pose: R and t move a world point into the camera frame.
  4. One matrix: homogeneous coordinates make P = K[R | t].
  5. Distortion: a real lens bends straight lines.
  6. The DLT: solve for P from known 3D points.
  7. Zhang's method: calibrate from a flat board (the hero's solver).
  8. Back to a ray: a pixel gives a direction, and two views give depth.
  9. The showcase: fly a camera around a cube and trace one pixel.
  10. The field guide: terms, numbers, code and the credit.
A near soda can and a far billboard lie on the same line of sight. What does one camera record about their distances?

Chapter 1

The Pinhole: Similar Triangles

Drag a point in front of a pinhole and watch its ray cross the image plane

Light through a tiny hole in a dark box paints an image on the far wall. That box is the pinhole camera: no lens, one point that every ray passes through.

Put the origin at the pinhole, the camera centre. The camera looks along its Z axis, the optical axis. X points right and Y points down, so images count rows from the top. The real image forms behind the hole, upside down. We draw an equivalent upright image plane in front of the hole, at a distance called the focal length.

Drag a point and follow its ray

Drag the pink point up, down, nearer or farther. Then change the focal length and watch the image plane move.

400 px

Illustrative toy. We draw the image plane to scale with f: 400 px sits at 0.8 of the way to the first tick.

Where does the ray cross the plane? Call the point's height Y and its depth Z, in metres, in the camera's frame. Call the focal length f. Call the crossing height on the image plane y. Two triangles share the angle at the pinhole, so y / f = Y / Z. From above, the same rule links the sideways offset X to its image coordinate x.

Say it aloud

x equals f times capital X, divided by capital Z.

x
little x where the ray crosses the image plane, measured sideways from the optical axis.
f
f the focal length: the distance from the pinhole to the image plane.
X
capital X the point's sideways offset from the optical axis, in metres.
Z
capital Z the point's depth: how far in front of the camera it is, in metres. It must be positive.
In plain words

Divide the offset X by the depth Z. That ratio is the direction of the point. Multiply it by f to get x. The same rule gives y from Y.

With numbers

Take f = 500 and a point at X = 2, Y = 1, Z = 5. Then x = 500 × 2 / 5 = 200 and y = 500 × 1 / 5 = 100. Move the point to (4, 2, 10), twice as far on the same ray: x = 200 and y = 100 again.

The divide by Z is perspective. Double the depth and the image shrinks by half. It is also the step that loses depth: only the ratios X / Z and Y / Z survive.

The failure, as symptom, measurement and fix

The symptom is a ghost: a point behind the camera shows up in the image. With Z = −5, the formula still returns a pixel, mirrored. To measure it, count points with Z ≤ 0 that your code projects. The fix is a guard: reject every point with Z ≤ 0 before you divide.

A pinhole camera with f = 400 sees a point at (X, Y, Z) = (3, 0, 6). What is its image x?

Chapter 2

Pixels: The Intrinsic Matrix K

Turn the four knobs of K and watch a grid of points move in the image

The pinhole gives x and y in metres from the optical axis. A camera reports pixel coordinates, counted from the top-left corner. Two changes bridge the gap.

  1. Scale. The sensor has some pixels per metre across and down. Fold those densities into f. You get the focal lengths in pixels, fx and fy.
  2. Shift. The optical axis hits the sensor at the principal point, near the image centre. Add its pixel position (cx, cy).

Call the pixel column u and the pixel row v. Call the focal length across, in pixels, fx, and the column of the principal point cx. X and Z are the point's offset and depth in the camera frame, as before.

Say it aloud

u equals f-x times X over Z, plus c-x.

u
u the pixel column, counted from the left edge.
fx
f-x the focal length in pixels across: f times the pixels per metre of the sensor.
X / Z
X over Z the direction of the point, from Chapter 1.
cx
c-x the column of the principal point, where the optical axis lands.
In plain words

Take the direction X / Z, scale it by fx, then shift it by cx. The row works the same way: v = fy × Y / Z + cy.

With numbers

A 640 by 480 camera with fx = fy = 500 and (cx, cy) = (320, 240). The point (2, 1, 5) gives u = 500 × 0.4 + 320 = 520 and v = 500 × 0.2 + 240 = 340. It lands right of and below the centre, as X > 0 and Y > 0 say it should.

The five numbers fx, fy, cx, cy and the skew γ go in one 3 by 3 matrix, the intrinsic matrix K. Skew couples u to Y when the pixel rows are not square to the columns. On real cameras it is about 0.

Read K by rows. Row one scales X by fx and shifts it by cx. Row two does the same for Y. Row three keeps the depth for the divide in Chapter 4. These are intrinsic numbers: they belong to the lens and sensor, so the camera carries them wherever it goes.

Turn the four knobs of K

Nine pink points sit on a grid 5 m in front of the camera. The yellow point is (2, 1, 5). Move each knob and watch the grid stretch or slide.

500 px
500 px
320 px
240 px

Illustrative toy. Grid points at X = −1.5, 0, 1.5 m and Y = −1, 0, 1 m, all at Z = 5 m. Points that fall off the 640 by 480 frame turn red.

The failure, as symptom, measurement and fix

The symptom is a small, steady error in every direction the robot computes. A common cause is to assume the principal point is the exact image centre. The real one can sit several pixels away. To measure it, calibrate and compare (cx, cy) with (320, 240). The fix is to use the calibrated values.

K has fx = fy = 400 and (cx, cy) = (300, 200). A point has X / Z = 0.5 and Y / Z = −0.25. Which pixel (u, v)?

Chapter 3

Where the Camera Stands: [R | t]

Orbit a camera around a point and read the point in the camera's own frame

So far each point came in the camera's frame. A robot's map, its goals and a checkerboard on the wall live in a fixed world frame. Before we project a world point, we must say where it is relative to the camera. That needs the camera's pose: which way it faces and where it stands.

Call the point's coordinates in the world frame PW and in the camera frame PC. Call the 3 by 3 rotation matrix R: it turns world directions into camera directions. Call the 3-vector t the translation: the world origin, written in camera coordinates.

Say it aloud

P-C equals R times P-W, plus t.

PC
P-C the point in the camera frame: (X, Y, Z), ready for Chapter 2.
R
R the rotation. Its three rows are the camera's x, y and z axes, written in world coordinates.
PW
P-W the same point in the world frame, in metres.
t
t the translation: where the world origin sits, seen from the camera.
In plain words

Turn the world point P-W into the camera's axes with R. Then add t to slide it so the camera centre is the origin. The result P-C is the point as the camera sees it.

With numbers

A camera stands at world (4, 0, 0) and faces down the world's −X axis. Its rows are R = [(0, 0, 1), (0, 1, 0), (−1, 0, 0)] and t = (0, 0, 4). Take P-W = (3, 1, 0). R times P-W = (0, 1, −3). Add t: P-C = (0, 1, 1). The point is 1 m in front of the camera, centred, 1 m low.

Orbit the camera and read PC

Seen from above. The teal camera stays 4 m from the world origin and faces it. Turn the orbit, and drag the pink point. The read-out gives the point in the camera frame.

90°

Illustrative toy in the world X and Z plane, with Y = 0. At 90° the camera is the worked example: centre (4, 0, 0), facing −X.

R and t are the camera's extrinsic parameters. They change every time the camera moves. K does not. Spin a camera on a tripod around a table: K stays fixed and [R | t] changes for every shot.

The failure, as symptom, measurement and fix

The symptom is a camera that seems to sit in the wrong place, often mirrored. The usual cause is to read t as the camera's position. The camera centre in world coordinates is C = −R⊤t. In the example that gives (4, 0, 0), not (0, 0, 4). To measure it, compute −R⊤t and compare it with where the camera stands. The fix is to name every pose by its two frames, for example "world to camera".

What do the extrinsic parameters [R | t] describe?

Chapter 4

One Matrix: Homogeneous Coordinates and P = K[R | t]

Slide a point along its ray and watch three numbers grow while the pixel stays put

The pixel rule divides by Z, and a matrix can only multiply and add. So we use homogeneous coordinates: give each point one extra number. Scaling all the numbers by any nonzero amount names the same point. The pixel (u, v) becomes (u, v, 1), which equals (2u, 2v, 2).

Multiply K by the camera-frame point (X, Y, Z). Call the three results a, b and w. The bottom row of K copies the depth, so w = Z.

Say it aloud

The pixel u, v equals a over w, and b over w.

u
u the pixel column.
v
v the pixel row.
a
a the first entry of K times the point: fx X + cx Z.
b
b the second entry: fy Y + cy Z.
w
w the third entry: the depth Z. It is the scale that the divide removes.
In plain words

Multiply K by the point to get a, b and w. Divide a and b by the last entry w. The matrix did the linear part; the divide did the perspective.

With numbers

Take K with fx = fy = 500 and (320, 240), times (2, 1, 5). Then a = 1,000 + 1,600 = 2,600, b = 500 + 1,200 = 1,700 and w = 5. So u = 2,600 / 5 = 520 and v = 1,700 / 5 = 340, as in Chapter 2.

Slide a point along its ray

The point moves along the ray through (2, 1, 5). Then drag the depth below zero.

5.0 m

The camera is K with fx = fy = 500 and (cx, cy) = (320, 240). The point is (0.4 Z, 0.2 Z, Z).

Along one ray, a, b and w all scale by one number, and the divide cancels it. A pixel names a ray, not a point.

Now chain the pose. Call the world point with an extra 1 P̃W, and the homogeneous pixel p̃ = (a, b, w). Put R and t side by side as one 3 by 4 block [R | t].

Say it aloud

p-tilde equals K times R-bar-t, times P-tilde-W.

p̃
p-tilde the homogeneous pixel (a, b, w). Divide by w to get (u, v).
K
K the intrinsic matrix, 3 by 3, from Chapter 2.
[R | t]
R-bar-t the 3 by 4 pose block from Chapter 3: R on the left, t as the fourth column.
P̃W
P-tilde-W the world point with a 1 added: (X, Y, Z, 1).
In plain words

First [R | t] moves the world point P-tilde-W into the camera frame. Then K turns it into a homogeneous pixel p-tilde. Divide by w. The product P = K[R | t] is the projection matrix, 3 by 4.

With numbers

Use K from above and the pose from Chapter 3. P has rows (−320, 0, 500, 1280), (−240, 500, 0, 960) and (−1, 0, 0, 4). The world point (−1, 1, 0, 1) gives p-tilde = (1600, 1700, 5). Divide by 5: pixel (320, 340).

P has 12 entries, but its scale cancels in the divide: 11 are free. That matches 5 in K, 3 angles in R and 3 in t.

The failure, as symptom, measurement and fix

The symptom is a phantom pixel. The world point (6, 1, 0) gives p-tilde = (−640, 20, −2), and the divide returns (320, −10) for a point behind the camera. To measure it, log w before the divide. The fix is to keep only points with w > 0.

A projection gives the homogeneous pixel (1040, 680, 2). Which pixel (u, v) is that?

Chapter 5

Lens Distortion: When Straight Lines Bend

Bend a straight grid into a barrel or a pincushion with one number

A pinhole sends light in straight lines. A real lens bends it, most of all near the edges of the image. Straight lines in the world then show up as curves. This is radial distortion: each pixel moves toward or away from a centre, along the radius.

KindWhat a pixel doesA square looksTypical lens
Barrelmoves inward, more at the edgebulging out, like a barrelwide angle, fisheye
Pincushionmoves outward, more at the edgepinched in at the sidestelephoto

Name the parts. The distortion centre (uc, vc) is usually the principal point. The ideal pinhole pixel is (u, v). Its squared distance from the centre is r² = (u − uc)² + (v − vc)². The distortion factor is k. The pixel the camera records is (ud, vd).

Say it aloud

u-d equals one plus k r-squared, times u minus u-c, plus u-c.

ud
u-d the distorted column: what the camera records.
k
k the distortion factor, per pixel squared. Negative gives barrel, positive gives pincushion.
r²
r-squared the squared distance of the ideal pixel from the centre.
u
u the ideal pinhole column from Chapter 2.
uc
u-c the column of the distortion centre.
In plain words

Take the offset u minus u-c. Scale it by 1 + k r-squared, which grows with distance from the centre. Add u-c back. The row v works the same way.

With numbers

Centre (320, 240), k = 1.0 × 10−6, ideal pixel (620, 440). The offsets are 300 and 200, so r² = 90,000 + 40,000 = 130,000. The scale is 1 + 0.13 = 1.13. So u-d = 1.13 × 300 + 320 = 659 and v-d = 1.13 × 200 + 240 = 466: 46.9 px outward, a pincushion. With k = −1.0 × 10−6 the scale is 0.87 and the pixel moves in to (581, 414).

Bend a straight grid

The faint grid is the ideal pinhole image. The blue grid is what the lens records. Drag k below zero for barrel, above zero for pincushion.

−1.0

Centre (320, 240) in a 640 by 480 image. The yellow dot follows the ideal pixel (620, 440). One-parameter model; real calibrations often add a second factor for r to the fourth.

A pixel near the centre barely moves. (330, 250) has r² = 200, so with k = 1.0 × 10−6 it moves by 0.003 px. Distortion lives at the edges. To undo it, you invert the scale. There is no closed form, so you iterate a few times or use a lookup table.

The failure, as symptom, measurement and fix

The symptom is good results near the image centre and bad ones near the corners. A ray from an uncorrected corner pixel points the wrong way. To measure it, photograph a straight edge near the border and check how far its points stray from a line. The fix is to calibrate k and undistort every pixel before you use it.

In the radial model with k < 0, what happens to a pixel far from the centre?

Chapter 6

Calibration by DLT: Solve for P from Known Points

Add known 3D points one by one and watch the recovered camera settle

A new camera comes with rough numbers for K at best. Calibration measures them from correspondences: known 3D points paired with their pixels. A classic target is two checkerboard walls at right angles.

Write the unknown 3 by 4 matrix P by rows: m1, m2, m3. A point P̃W seen at (u, v) obeys u = (m1 · P̃W) / (m3 · P̃W). Multiply out the bottom: u (m3 · P̃W) − m1 · P̃W = 0, and the same for v with m2. Both are linear in the 12 entries of P. This is the direct linear transformation (DLT).

Stack the 12 entries in a column m, and two rows per point into A, 2n by 12. With noise, only m = 0 solves A m = 0, and it means nothing. So fix the length of m at 1 and make A m as small as you can.

Say it aloud

m-star is the m that makes the length of A times m smallest, with the length of m held at one.

m*
m-star the answer: the 12 entries of P, stacked.
argminm
the argmin over m the m that makes what follows smallest, not the smallest value itself.
‖ ‖
the length of the square root of the sum of squared entries.
A
A the stacked equations: two rows per correspondence, 12 columns.
m
m a candidate for P, as a column of 12 numbers.
In plain words

Among all m of length 1, keep the one that A sends closest to zero. That is the last right singular vector of A, the direction A stretches least.

With numbers

A tiny case: A has rows (3, 0), (0, 1) and (0, 1). The unit vector m = (1, 0) gives A m = (3, 0, 0), squared length 9. The unit vector m = (0, 1) gives (0, 1, 1), squared length 2. The SVD returns (0, 1), the smaller of the two.

P has 11 free numbers and each point gives 2 equations: at least 6 points. P's left 3 by 3 block equals K R, and an RQ decomposition splits it into that upper-triangular K and rotation R. Then t = K−1 times P's fourth column.

Fit a camera to known points

Blue dots: corners in the fit. Purple crosses: where the recovered camera puts them. Rings: 10 corners kept back to check. Add points, raise the noise, then use one wall.

8
1.0 px

Illustrative toy: a true camera with fx = fy = 500, (320, 240), turned 20° and 6 m from a two-wall rig of 50 corners. The solver is the DLT above, with the data scaled first for stable numbers.

The fit error is the pixel gap on the fitted points. The check error is the gap on points the fit never saw. With 1 px noise, a typical run looks like this:

Points usedFit errorCheck error
80.7 px2.6 px
201.2 px0.9 px
401.3 px0.5 px

The failure, as symptom, measurement and fix

The symptom is a wild camera from points that all lie on one wall. A plane leaves many m that fit equally well. To measure it, compare the two smallest singular values of A: if they are close, nothing pins the answer. Use a rig with depth, or Zhang's method.

Why does the DLT take the smallest singular vector of A, with the length of m fixed at 1?

Chapter 7

Zhang's Method: Calibrate with a Flat Checkerboard

Guess the focal length and watch the board's two axes bend away from a right angle

A two-wall rig is hard to build; a printed checkerboard is easy. Zhang's method (Zhengyou Zhang, 2000) calibrates from several photos of one flat board at different tilts. OpenCV's calibrateCamera uses it for flat targets.

Put the board on the world plane ZW = 0. The third column of R then multiplies zero and drops out. Each photo becomes a 3 by 3 homography H that sends board points (X, Y, 1) to pixels. Up to scale, H = K [r1 r2 t]. Here r1 and r2 are the board's axes in the camera frame. The DLT of Chapter 6 finds each H from 4 or more corners.

Call the first two columns of H h1 and h2. Undo the lens: K−1h1 and K−1h2 are r1 and r2 times one scale. So they meet at a right angle, with equal length. Call B = K−⊤K−1 the "lens undo, squared". It holds only K.

Say it aloud

h-one transposed, times B, times h-two, equals zero.

h1⊤
h-one transposed the first column of this photo's homography, laid on its side.
B
B K-inverse transposed times K-inverse: a symmetric 3 by 3 that holds only the intrinsics.
h2
h-two the second column of the homography.
In plain words

Undo the lens on h-one and h-two. Take the dot product of the two results. It must be zero, because the board's axes are at right angles. A second rule, h-one-B-h-one = h-two-B-h-two, says the axes have equal length.

With numbers

With made-up numbers: the device's photo 1, true K (fx 520, fy 500). The undone axes meet at 90.0°, so the product is 0. Guess 75% of the focal lengths (fx 390, fy 375). The axes now meet at 95.1° and their lengths differ by 4%. That guess breaks both rules.

Guess the focal length

One panel per photo. Purple arrows: the board's axes after undoing your guessed K. Slide until all three meet at 90°, then try face-on photos.

75%

Illustrative synthetic camera (fx 520, fy 500, cx 330, cy 235). The guess scales fx and fy together and keeps the true principal point.

Count. B is symmetric with 6 entries and a free scale: 5 unknowns. Each photo gives 2 equations, and zero skew gives 1 more. So 1 photo gives 3, too few; 2 photos give 5, just enough. More photos average out the noise.

  1. Detect the corners in each photo and fit its H with the DLT.
  2. Stack the two rules from every photo. Solve for B with the SVD.
  3. Read K from B with Zhang's closed-form formulas.
  4. Get each photo's R and t from K−1H.
  5. Refine all of it, plus distortion, by least squares on the reprojection error.

The failure, as symptom, measurement and fix

The symptom is a focal length that jumps between runs. A common cause is photos taken face-on. Switch the device to face-on: every guess gives 90° and equal lengths, so the photos say nothing about the focal length. To measure it, check the spread of fx over repeated calibrations. The fix is to tilt the board 20° to 45° in several directions, and to fill the image.

Why does one photo of a flat board not calibrate a camera, even with zero skew assumed?

Chapter 8

Back-Projection: From a Pixel to a Ray

Turn on a second camera and watch two rays pin a point in depth

Calibration gave us K, R and t. Can we now take a pixel back to its 3D point? No. P is 3 by 4, so it has no inverse. The divide by w threw the depth away, and no calibration can bring back a number that was never recorded.

We can recover the ray. Call the pixel (u, v) and write it as (u, v, 1). Undo the intrinsics with the inverse matrix K−1. Call the result d, the ray's direction in the camera frame.

Say it aloud

d equals K-inverse times the column u, v, one.

d
d the ray's direction in the camera frame. Its last entry is 1.
K−1
K-inverse undoes the scale and shift of K.
(u, v, 1)⊤
the column u, v, one the pixel in homogeneous form.
In plain words

Subtract the principal point from the pixel and divide by the focal lengths. With zero skew, that is all K-inverse does. Every point λ times d, with λ > 0, lands on this pixel. The depth λ is unknown.

With numbers

K with fx = fy = 500 and (320, 240), pixel (520, 340). d = ((520 − 320) / 500, (340 − 240) / 500, 1) = (0.4, 0.2, 1). At λ = 5 the point is (2, 1, 5), the one from Chapter 1. At λ = 10 it is (4, 2, 10). Both give the same pixel.

Way to get depth backWhat it adds
Stereoa second calibrated camera a known distance away; intersect the two rays
Structure from motionone moving camera; match features across frames (Lesson 9)
Depth from focusrefocus until sharp; the lens formula gives the distance
A priora known size or a known ground plane fixes λ

Pin a point with two rays

Seen from above. Camera A alone knows only a ray. Turn on camera B, drag the point and change the gap between the cameras. The shaded patch is where 1 px of noise lets the point hide.

0.30 m

Illustrative toy: two parallel cameras with f = 500 px. The patch spans the rays half a pixel either side of each true ray, so the disparity is off by up to 1 px.

Two rays from a known gap cross at the point. This is triangulation. The gap is the baseline. With a 0.3 m baseline, a point 5 m away and 1 px of noise, depth moves by about 0.17 m. Double the distance and that error grows about four times.

The failure, as symptom, measurement and fix

The symptom is depth that jitters for far objects. The baseline is too short for the range. To measure it, watch the spread of the depth of a still target over many frames. The fix is a wider baseline, or a closer target.

With a perfectly calibrated single camera, back-projecting a pixel gives you what?

Chapter 9

Showcase: A Pinhole Camera You Can Fly

Orbit a camera around a cube and trace one corner from metres to pixels

Every piece now runs at once. A cube stands at the world origin. A camera circles it. Each corner goes world, then [R | t], then camera frame, then K and the divide, then distortion, then the drawn pixel. The trace under the device follows the yellow corner through every step.

Fly the camera

Left: the world from above. Right: the image. Orbit the camera, move it in or out, change f, and switch the lens.

35°
7.0 m
520 px

Illustrative toy: a 2 m cube and a 640 by 480 image with (cx, cy) = (320, 240). The camera sits 1 m above the cube's centre and aims at it. Barrel and pincushion use k = ∓0.8 × 10−6.

Things to try. Raise f: the cube grows and corners leave the frame, a narrower view. Move in close: near corners grow much faster than far ones, the divide by Z at work. Switch to barrel: straight edges bow, most at the image border.

Chapter 10

Field Guide

Keep the terms, the numbers, the code and the next steps in one place

A camera maps a world point to a pixel with P = K[R | t], then the lens bends it. K holds 5 numbers that belong to the camera. [R | t] holds 6 that change as it moves. Calibration recovers them from known points; a flat board needs two or more tilted photos. Going back, a pixel gives only a ray.

TermRuleNumber to remember
Pinholex = f X / Zf 500, (2, 1, 5): (200, 100)
Pixelsu = fx X / Z + cx(2, 1, 5): pixel (520, 340)
PosePC = R PW + t, centre −R⊤t(3, 1, 0) to (0, 1, 1)
Homogeneous(u, v) = (a / w, b / w)(2600, 1700, 5): (520, 340)
ProjectionP = K[R | t], 3 by 411 free numbers
Distortionud = (1 + k r²)(u − uc) + uck 10−6: corner moves 46.9 px
DLTmin ‖A m‖, ‖m‖ = 1at least 6 points, not coplanar
Zhangh1⊤B h2 = 0, h1⊤B h1 = h2⊤B h22 photos with zero skew, 3 without
Back-projectiond = K−1(u, v, 1)(520, 340): ray (0.4, 0.2, 1)

Checklist for a camera on a robot

The core, in code

python
import numpy as np

def project(K, R, t, P_w, k=0.0):
    P_c = R @ P_w + t                       # world -> camera frame
    if P_c[2] <= 0: return None             # behind the camera
    a, b, w = K @ P_c                       # homogeneous pixel
    u, v = a / w, b / w                     # the perspective divide
    cx, cy = K[0, 2], K[1, 2]
    s = 1 + k * ((u - cx)**2 + (v - cy)**2)  # radial distortion
    return s * (u - cx) + cx, s * (v - cy) + cy

def back_project(K, u, v):
    return np.linalg.inv(K) @ np.array([u, v, 1.0])   # a ray; depth unknown

# Calibration from board photos (Zhang's method, then refinement):
# import cv2
# rms, K, dist, rvecs, tvecs = cv2.calibrateCamera(obj_pts, img_pts, (640, 480), None, None)

Where this sits in the series

Keep going

Based on Stanford AA 274A, Principles of Robot Autonomy I. This page re-teaches the course's lesson on camera models and calibration in our own words, devices and toy numbers. Zhang's method is from Zhengyou Zhang, "A Flexible New Technique for Camera Calibration", IEEE TPAMI, 2000.

The takeaway. A camera keeps direction and drops depth. Learn its K once, from tilted photos of a board, and every pixel becomes an exact ray.

Now press Present or Teach and explain from memory: the pinhole, K, the pose, the divide, distortion, the DLT and Zhang's two rules. Then go back to the calibration bench, take 1 photo, and say why it cannot solve.

Principles of Robot Autonomy I · Stanford AA 274A · Lesson 8: Camera Models and Calibration
Next: Features, SfM and RANSAC · Back to Gleams