Type 23 mm for a checkerboard with 25 mm squares, and every stereo depth comes out 8% short. The reprojection error stays at 0.42 px, so every check stays green. Only a length you measure yourself catches it.
Drag the square size away from 25 mm and watch the gripper close on air while the dashboard says pass. Then press the tape check. Then we build, one calibration at a time, what each one solves, what makes it observable, and the trace each fault leaves.
You need matrix times vector, the pinhole camera and a little Python. We build the rest from zero.
Lesson 5 of the Robotics Engineering track. Before: Lesson 4, The Sensor Suite. Next: Lesson 6, The SLAM Frontend. Lesson 4 asked what each sensor lies about. This lesson asks how we measure the numbers that tie the sensors together, and how we know when they are wrong.
Illustrative rig, numbers from our simulation: 20 synthetic views of a 9 by 6 board with 25 mm squares, 0.3 px corner noise, calibrated with OpenCV's calibrateCamera and stereoCalibrate. The RMS error was 0.42 px for every typed size; K was identical; the baseline came out 0.120 m at 25 mm and 0.110 m at 23 mm. The mug sits 0.300 m from the cameras.
Chapter 0
Sort a robot's calibrations into three kinds, and find the fault that no residual can see
A picking arm carries a stereo camera. Its calibration passed with a reprojection error of 0.42 px. Weeks later the gripper closes 24 mm short of every mug. The cause is one line in a file: someone typed 23 mm for checkerboard squares that measure 25 mm.
So every length from that calibration is 23/25 = 0.92 of the truth. The stereo baseline is 0.92 of the truth, so every depth is too. A mug at 0.300 m reads 0.276 m. The reprojection error did not move, because nothing in the images changed. Chapter 3 proves why.
A robot carries three kinds of calibration. Intrinsics map a ray to a pixel: focal lengths, principal point and lens distortion. Extrinsics place each sensor on the robot: one rigid transform per sensor, as in Lesson 1. Temporal calibration finds the offset between two sensors' clocks; Lesson 2 built the clocks.
| Kind | Unknowns | Measured from | Fails silently when |
|---|---|---|---|
| Intrinsic | 4 to 5 for K, 2 to 5 for the lens | a flat board, many tilted views | the board size is wrong, or the views never reach the image corners |
| Extrinsic | 6 per sensor pair | a shared target, or the same motion seen by both | the motion never rotates, or rotates about one axis only |
| Temporal | 1 offset per clock pair, plus its drift | image motion against gyro rate | nothing moves, or the turn rate never changes |
The residual is the gap between where a feature appears and where the calibrated model predicts it. It is the only alarm a running robot has. The device asks it about five faults.
The top bar is the residual the robot measures while it drives. The yellow line is the noise floor. The bottom bar is the true error the fault causes. Pick a fault.
Illustrative drive, the same seeded model as the Chapter 9 fault injector: 300 features at 1 to 20 m depth, up to 400 px from the image centre, image speeds up to 300 px/s, 0.3 px noise, f = 800 px. The true errors are the faults themselves.
Four faults lift the residual above its 0.29 px floor, from 0.76 px for the lens to 9.4 px for the lever arm. The typo leaves it at 0.29 px while every depth is 8% wrong. A fault that scales the whole world is invisible to any test that compares images with images.
Symptom: grasps and measured distances are short by the same percentage at every range, and every calibration check passes.
Measure: measure a known length with the calibrated sensor: a 1.000 m bar reads 0.920 m.
Fix: measure the printed squares with calipers, because printers rescale pages. Store the size with the board's ID, and put the bar check in the acceptance test.
Chapter 1
Turn a flat board's known corners into a 3 by 3 matrix, and read a test for K out of it
Hold a printed checkerboard in front of the camera. You know each inner corner's place on the board in metres; the detector finds its place in the image in pixels. One view of a 9 by 6 board links 54 known points to 54 pixels.
Put the board's frame on the board: x and y along the squares, z out of the board. Then every corner has Z = 0. The camera model from VNAV Lecture 5 multiplies the point by K [r₁ r₂ r₃ t], and the zero removes r₃. What is left is a 3 by 3 matrix acting on (X, Y, 1). It is a homography: a map from one plane to another.
Name the parts. K holds the focal length f and the principal point c. r₁ and r₂ are the board's x and y directions in the camera frame, and t is its origin. λ (lambda) is a scale no pixel can see. The homography H is:
H equals lambda times K times the matrix whose columns are r-one, r-two and t.
Write the board's two axis directions r-one, r-two and its origin t as three columns. Multiply by K. Any scale lambda gives the same pixels. The detector's 54 matches pin down H up to that lambda.
With made-up numbers: the board faces the camera 0.6 m away, so r-one = (1, 0, 0), r-two = (0, 1, 0), t = (0, 0, 0.6). With lambda = 1, H has columns (800, 0, 0), (0, 800, 0) and (192, 144, 0.6). The corner at X = 0.1 m, Y = 0 maps to (80 + 192, 144, 0.6), so u = 272 / 0.6 = 453.3 px and v = 240 px. The pinhole gives the same: 800 × 0.1 / 0.6 + 320 = 453.3.
Now undo K: K⁻¹h₁ = λ r₁ and K⁻¹h₂ = λ r₂. The two undone columns must have the same length and meet at 90°, because r₁ and r₂ do. With the right K they pass this test in every view. With a wrong K they fail it, unless the board faces the camera squarely.
Left: the board in the image. Right: the two columns after undoing your guessed K. Guess wrong, then tilt.
Illustrative camera: f = 800 px, c = (320, 240). A 9 by 6 board, 0.6 m away, no noise, so the test is exact.
Face-on, every guess passes. With f = 700 px and 30° of tilt about x, the lengths differ by 3%; add 20° about y and the angle opens to 92.2°. Tilt creates this information (Chapter 4).
Symptom: one view's reprojection error is 3 px while the others sit near 0.4 px.
Measure: print the error per view, and fit a plane to that view's corners in 3-D.
Fix: a bent board breaks Z = 0, so no homography fits it. Mount the print on glass or flat aluminium, and drop views where the board flexed.
Chapter 2
Stack each view's test into a linear system, and count how many views it needs
Chapter 1's test has K inside it twice, which is hard to solve. Zhang's trick (IEEE TPAMI, 2000) is to name the product instead. Call B the matrix K⁻¹ transposed times K⁻¹. B is symmetric, so it has 6 entries, and we know it only up to scale: 5 numbers to find. Call the first two columns of a view's homography h₁ and h₂. The test becomes two equations:
h-one transpose B h-two equals zero; and h-one transpose B h-one equals h-two transpose B h-two.
Measured through B, column h-one times column h-two must give zero: the board's axes are square. Column h-one times itself must equal h-two times itself: the axes have equal length. Lambda appears on both sides and cancels, so it never needs to be known.
With Chapter 1's face-on view, h-one = (800, 0, 0) and h-two = (0, 800, 0). The first equation gives 800 × 800 × B₁₂ = 0, so B₁₂ = 0: no skew. The second gives 640,000 B₁₁ = 640,000 B₂₂, so f-x = f-y. Neither says what f is. A face-on view only confirms the shape of K.
Each equation is linear in the 6 entries of B, so each view adds two rows to a matrix V, and we solve V b = 0 with an SVD. Count: 5 unknowns, 2 rows per view, so 3 views give a unique answer. Two views work if you also assume zero skew, which modern sensors justify. Zhang's paper states both cases.
Each bar is a singular value of V, on a log scale. A unique answer needs five of them above zero. Add views and watch the fifth bar rise.
From our run of the lab's kernel: views tilted 20° about different axes, 0.3 px corner noise, 120 seeded trials per row. The spread of f is the standard deviation over the trials. The zero-skew row is scaled to match the others.
With 3 views, f comes out with a spread of 29 px at 0.3 px of corner noise. With 6 views it drops to 6.3 px. The closed form is a first guess. OpenCV's calibrateCamera then refines K, the distortion and every pose together, by minimising the reprojection error with Levenberg-Marquardt (VNAV Lecture 9). You write the closed form in the lab.
Symptom: the closed form returns NaN for f, or a focal length of several thousand pixels.
Measure: the fifth singular value of V over the first. Near zero means B is not pinned, and noise can make it non-positive, so a square root fails.
Fix: add views tilted in different directions, well beyond the minimum of three.
Chapter 3
Follow a wrong square size through Zhang's equations, and see why only a measured length catches it
Tell the solver the squares are 23 mm. The corners in the image do not move: they are photons. Only the model coordinates shrink, from (X, Y) to (sX, sY) with s = 23/25 = 0.92. To send smaller coordinates to the same pixels, the fitted H multiplies h₁ and h₂ by 1/s and keeps h₃. The fit is exact, so the residual does not change.
Now put the new columns into Zhang's two equations. Each side has one h₁ or h₂ on the left and one on the right, so each side picks up 1/s², and it cancels. B is unchanged, so K is unchanged, and so is the lens model. The scale has to go somewhere. It goes into the translation, which we recover from one view like this:
t equals K inverse times h-three, divided by the length of K inverse times h-one.
Undo K on h-three to get lambda times t. Find lambda as the length of K inverse h-one, since r-one is a unit vector. Divide. If a typo made h-one longer by 1/s, lambda grows by 1/s, and t shrinks by s.
From the lab's run: the board in view 0 is 0.6004 m away. Told 23 mm, the solver puts it at 0.5524 m: 0.5524 / 0.6004 = 0.920, and f stays 800.000 px. Our OpenCV cross-check on 20 views agrees: RMS 0.4067 px both times, f-x 804.373 px both times, and every view's distance scaled by exactly 0.920.
Every metric number downstream inherits s. A stereo calibration recovers the baseline from board poses: ours came out 0.1199 m at 25 mm and 0.1104 m at 23 mm. Depth is focal length times baseline over disparity, so every depth shrinks by 0.92. A hand-eye calibration that uses board poses shrinks its lever arm the same way.
Three ratios against the truth. Purple is the focal length, yellow the reprojection error, warm the recovered distance. Drag the typed size.
Numbers from the lab's noiseless kernel (focal length and distance) and our noisy OpenCV run (residual 0.41 px). The true squares are 25 mm and the true distance is 0.600 m.
Symptom: the map of a 40 m by 25 m hall comes out 36.8 m by 23.0 m, and loop closures look perfect.
Measure: one external length: a surveyed bar, two fiducials a known distance apart, or the stereo depth against a LiDAR range.
Fix: measure the board, type its size once into a board file, and fail the calibration if the bar check is off by more than 0.5%.
Chapter 4
Measure how fast the focal length's spread falls as the board tilts, and why one tilt axis is never enough
Chapter 1's face-on board could not tell f = 700 from f = 800. A tilted board foreshortens, and how much it foreshortens depends on f. Tilt is the information.
Each view's two rows of V depend only on r₁, r₂ and K, not on t. So eight views tilted the same way about the same axis give the same two rows eight times. V keeps rank 2 at any tilt, and K has a whole family of answers. Tilt the views about different axes and the rows differ. A matrix is observable here when its fifth singular value is clearly above zero.
How fast does it improve? We ran the lab's experiment: eight views, the tilt axis turning 45° from view to view, 0.3 px corner noise, 120 trials per tilt.
| Tilt | Spread of f | Spread of c-x | Failed solves |
|---|---|---|---|
| 1.1° | 3,172.8 px | 74.3 px | 30 of 120 |
| 5.7° | 31.4 px | 3.2 px | 0 |
| 11.5° | 10.6 px | 1.9 px | 0 |
| 20.1° | 5.4 px | 1.5 px | 0 |
| 28.6° | 3.9 px | 1.4 px | 0 |
From 1.1° to 20.1° the spread of f falls 589 times, from 3,173 px to 5.4 px. At 1.1° a quarter of the solves return no real number. The noiseless fifth singular value, divided by the tilt squared, stays flat to within 7.4%: observability grows as the tilt squared.
Left: the eight board views. Right: the spread of f against tilt, and 30 trial answers as dots around the true 800 px. Drag the tilt, then make all views share one axis.
From our run of the lab's kernel at 14 tilts, seeded. With one shared axis the noiseless fifth singular value is about 10⁻¹⁷ of the first: machine zero, so the answer is arbitrary and no spread is quoted.
Symptom: two calibrations of the same camera, an hour apart, disagree by 30 px in f.
Measure: the standard deviations OpenCV's calibrateCameraExtended returns for each intrinsic, or the fifth singular value of V.
Fix: tilt the board 20° or more, toward and away, left and right, so the tilt axis changes between views.
Chapter 5
Read the one number a calibration reports, and see a lens model go wrong where the board never went
A calibration reports one number. It projects each board corner through the fitted model and compares it with the detected corner. Call the number of corners N, the detected pixel of corner i xi, and the reprojected pixel x̂i (x-hat-i). The RMS reprojection error is:
RMS equals the square root of one over N times the sum over i of the squared length of x-i minus x-hat-i.
For each corner, measure the distance in pixels between x-i and x-hat-i. Square each distance, average over the N corners, and take the square root.
With corner noise of 0.3 px on each axis, a perfect model leaves distances of about the square root of 2 times 0.3 = 0.42 px, because OpenCV measures the 2-D distance. Our 20-view run reported 0.407 px: slightly less, because the fitted parameters absorb a little of the noise.
The sum runs only over corners you showed it. Lens distortion is a polynomial in the distance r from the image centre (Lesson 4, VNAV Lecture 5). A polynomial fitted on small r says nothing reliable about large r.
The curves show how far the lens moves a point, against its distance from the image centre. Pink is the true lens, purple the fit. Blue marks where corners were seen. Pick a coverage.
From our OpenCV run: a lens with k₁ = −0.28 and k₂ = 0.10, f = 800 px, 640 by 480, 15 seeded views (12 stayed in frame at full coverage), 0.3 px noise, five distortion terms fitted. The image corner is 400 px from the centre.
Centre-only views give an RMS of 0.405 px, the same as the half-frame run. Yet at the image corner the fit says the lens moves a point 1.4 px outward, while the truth is 25.5 px inward: 27 px wrong. The full-frame fit gives −25.3 px there. Fixing the third coefficient at zero, a normal choice for a non-fisheye lens, cuts the centre-only error to 6 px but does not remove it.
Symptom: straight shelf edges bow near the image borders after undistortion, and the calibration reported 0.4 px.
Measure: plot every detected corner on one image. Note the largest radius reached against the 400 px corner radius.
Fix: put the board in all four corners and along the edges, and fix k₃ (OpenCV's CALIB_FIX_K3) unless the lens is a fisheye.
Chapter 6
Recover the rotation between two sensors by lining up their motion arrows
A LiDAR sits under a camera. We need the rigid transform between them, but the LiDAR cannot see printed squares. Both sensors ride one rigid body, so they feel the same motion, each in its own frame.
Call A the camera's motion between two instants, from the board or from visual odometry. Call B the LiDAR's motion over the same interval, from scan matching. Call X the LiDAR's pose in the camera frame, TCL in Lesson 1's notation. All three are 4 by 4 rigid transforms:
A times X equals X times B.
Take a point in the LiDAR frame. Route one: move it with B, then carry it into the camera frame with X. Route two: carry it with X, then move it with A. A rigid mount makes the routes agree.
With made-up numbers, on the floor: X turns 90° and shifts (0.30, 0.10) m. The LiDAR turns 90° and moves (0.50, 0) m, so the camera reports a 90° turn and (0.40, 0.30) m. Translations: A X gives (−0.10, 0.30) + (0.40, 0.30) = (0.30, 0.60); X B gives (0, 0.50) + (0.30, 0.10), the same.
Split it. The rotation part says RA RX = RX RB, and it has no translation in it, so solve it first. Write each rotation as its rotation vector, axis times angle. Then each motion i gives a pair of arrows with ai = RX bi: RX turns the LiDAR's arrows onto the camera's.
Finding the rotation that best lines up matched arrows is the orthogonal Procrustes problem. Sum the outer products, take an SVD, and keep a rotation, not a mirror:
M = Σi ai biT → M = U Σ VT → RX = U · diag(1, 1, det(U VT)) · VT
By hand: let RX be 90° about z. LiDAR turns of 0.40 rad about z and 0.55 rad about y give a1 = 0.40 ez and a2 = −0.55 ex. M has singular values 0.3025, 0.16 and 0; the determinant fixes the last direction, and RX comes back exactly. This is Park and Martin's method (1994). Tsai and Lenz (1989) showed that it takes two motions with non-parallel axes.
Blue: the camera's rotation vectors. Dashed light blue: the LiDAR's. Purple: the LiDAR's after the estimated rotation. Pick a motion set.
The lab's rig: X turns about 90°; noiseless motions of 0.35 to 0.70 rad; our NumPy run. On a separate test, OpenCV's calibrateHandEye (Tsai, Park, Daniilidis) matched this solve to within 10⁻¹²°.
Symptom: a ground robot's camera-to-LiDAR yaw changes by degrees between calibration drives.
Measure: the singular values of M. A second value near zero means every motion turned about one axis, so the turn of the mount about that axis is free.
Fix: a robot that only yaws cannot observe it from motion, nor the lever arm's height. Add a target both sensors see, or tilt the rig by hand during the run.
Chapter 7
Solve for the offset between two sensors, and price how much turning it needs
An intern drives 60 m down a straight aisle, logs both sensors and runs the extrinsic solve. It converges, and reports a lever arm of zero.
With RX known, the translation half of A X = X B is linear. Call tX the lever arm: where the LiDAR sits in the camera frame. Call RA and tA the camera's rotation and move, and tB the LiDAR's move:
R-A minus I, times t-X, equals R-X times t-B, minus t-A.
Turn the LiDAR's move t-B into the camera frame and subtract the camera's move t-A. What is left is the extra arc the offset t-X swept while the robot turned by R-A. Stack this for every motion and solve by least squares.
Chapter 6's floor example: R-A minus I is [−1 −1; 1 −1], with determinant 2. The right side is (0, 0.50) − (0.40, 0.30) = (−0.40, 0.20). Solving gives t-X = (0.30, 0.10) m, the truth.
Now drive straight. RA = I, so the left side is zero times tX, and every lever arm fits. Two points on a body that translates without turning move the same way. Only a turn makes the farther sensor sweep a larger arc. The least-squares solver returns the smallest answer that fits: zero, both sensors in one place.
How much turning? In the plane, both singular values of R(θ) − I equal 2 sin(θ/2). So 1 cm of error in a measured move becomes 1 cm / (2 sin(θ/2)) of lever-arm error: 0.29 m at 2°, 5.7 cm at 10°, 1.9 cm at 30°, 0.7 cm at 90°. Our 3-D Monte Carlo with 10 random-axis motions agrees: 0.19 m at 2°, 1.3 cm at 30°.
Left: the true LiDAR place in pink, 30 trial estimates in purple. Right: error against turn; yellow is the one-motion law. Drag the turn.
Illustrative planar solve, live in your browser: 6 motions per trial, turning ±θ with seeded random moves, 1 cm of noise on each measured camera move, RX known, 30 trials. True lever arm (0.30, 0.10) m.
When both sensors can see a target, it is faster. A board with holes or sharp edges gives matched points in the image and the scan, and one rigid alignment solves the extrinsic. Targetless methods align image edges with depth jumps (Levinson and Thrun, 2013), or maximise mutual information between LiDAR intensity and image brightness (Pandey et al., 2012). Lesson 1, Chapter 6 shows each error in pixels: 1° of rotation moves every point 14 px; a 2 cm shift moves points 16 px at 1 m.
Symptom: the lever arm reads (0, 0, 0), or changes by tens of centimetres between runs.
Measure: the smallest singular value of the stacked (RA − I). Near zero means some direction of the lever arm is not pinned.
Fix: drive figure-eights with sharp turns, or take the lever arm from the CAD model and calibrate only the rotation.
Chapter 8
Estimate a clock offset from image motion, price its precision, and see when it hides behind a bias
Lesson 2 built the clocks, the stamps and a cross-correlation for a recorded bag. Here the offset becomes one more state the estimator solves for.
The camera stamps a frame t, but it took the frame at t + td. A feature that crosses the image at image velocity u̇ (u-dot), in pixels per second, lands that much motion away from the prediction. Call the leftover r:
r equals u-dot times t-d.
Multiply the feature's speed u-dot by the stamp's lateness t-d. The slope of r against u-dot is t-d, so the estimator adds one Jacobian column.
With illustrative numbers: f = 800 px and a 0.30 rad/s turn give u-dot = 240 px/s. With t-d = 18.4 ms, r = 240 × 0.0184 = 4.42 px, 14.7 times a 0.3 px tracker noise. Driving straight, r is near zero.
The Cramér-Rao bound (Fisher Information) gives the smallest possible spread. Call the tracker noise σpx and the feature count N:
sigma t-d equals sigma pixels over root N times u-dot.
Divide the tracker noise sigma-pixels by the image speed u-dot and by the square root of the feature count N. Ten times more features buys about 3.2 times; ten times more motion buys 10.
With illustrative numbers: 0.3 / (√200 × 240) = 88 µs from one frame. At 5 px/s, 200 features and a 5 ms prior leave 3.2 ms. At u-dot = 0 the frame teaches nothing.
A steady turn is a worse trap. Over a 1 s window, a gyro bias b also shifts every feature by a constant, f · b pixels. When u̇ is the same everywhere, the two columns are proportional and the data cannot split the residual. Rate reversals separate them.
Dashed: the prior, 5 ms by 10 mrad/s. Purple: the posterior after 200 features. Raise the speed, then add reversal.
Illustrative linear-Gaussian update, exact in your browser: f = 800 px, a 1 s window (so each bias unit moves pixels by 800), σpx = 0.3 px, 200 features. Our NumPy run gives the same: constant rate 4.945 ms with correlation −0.9998; half reversed 0.088 ms with correlation 0.
At a constant rate, 200 features at 240 px/s move the offset's spread from 5.000 ms only to 4.945 ms, with correlation −0.9998. With half turning the other way: 0.088 ms. The bias converges in both cases, so a dashboard that watches it stays green. Kalibr (Furgale et al., 2013) estimates the offset over a recording; Li and Mourikis (2014) estimate it online. Both need this kind of motion.
From a bag, the quickest estimate is a correlation of gyro rate against camera rate. The lab adds a parabola through the peak, which finds 18.384 ms from 5 ms samples. A rolling shutter adds a per-row offset (Lesson 4). Clocks drift too: an illustrative 40 ppm crystal gains 2.4 ms a minute, so let td wander slowly.
Symptom: the offset estimate walks by milliseconds every frame while the robot stands still.
Measure: its spread is not shrinking while its correlation with the gyro bias is near −1. A 0.5 px noise residual then moves it 1.96 ms, through the cross-covariance alone.
Fix: freeze the offset when the window has no rate change: zero its row of the gain. Inflating the noise 100 times still moves it 0.28 ms.
Chapter 9
Regress the residual on four covariates, and let each slope name a fault in its own units
Calibration does not stay done. A bump knocks a mount, heat bends a bracket, a driver update moves the time stamp. A running robot can watch its own residuals, because each fault multiplies a different physical quantity. That quantity is the fault's covariate.
| Fault | The residual grows with | Slope means |
|---|---|---|
| Mount yaw δθ (or principal point) | nothing: a constant | intercept a = f δθ |
| Lever arm δt | 1/Z, inverse depth | b = f δt |
| Time offset td | u̇, image speed | c = td |
| Lens δk₁ | r³/f², radius cubed | d = δk₁ |
| Board size or baseline | nothing at all | invisible: needs a measured length |
Fit all four at once by least squares: residual = a + b (1/Z) + c u̇ + d r³/f². Each coefficient comes with a t-statistic, its value over its standard error. Far above about 5 means the fault is real. Fitting them together matters: one slope fitted alone soaks up the others.
Inject faults. The scatter shows the residual against one covariate, with the other fitted terms removed, and the purple fitted line. The bars show each fault found, with pink ticks for the truth.
Illustrative drive, seeded, the same model our NumPy script fits: 300 features, 1/Z from 0.05 to 1 per metre, radius up to 400 px, image speed ±300 px/s, 0.3 px noise, f = 800 px. A fault is flagged when its |t| exceeds 5.
With an intercept, each fault comes back alone: yaw 0.299° with t = 94, lever 2.00 cm with t = 260, offset 18.44 ms with t = 191, lens 0.0146 with t = 25. Now turn the intercept off with only the yaw injected. The constant has nowhere to go, so it leaks: a 0.55 cm lever arm (t = 20) and a lens error (t = 12.5) appear that do not exist.
The monitor can also live inside the estimator. OpenVINS (Geneva et al., ICRA 2020) can carry the intrinsics, the camera-IMU extrinsics and the time offset as filter states. Keep an independent check anyway: a state that absorbs a fault also hides it, and nothing absorbs the square typo.
Symptom: after a bump, the monitor flags a lever-arm error and a lens error at the same time.
Measure: refit with an intercept. If the intercept carries it all, the mount yawed.
Fix: re-run only the extrinsic rotation. Leave the lens alone.
Chapter 10
Keep the calibration table, the code and the checks in one place
Every calibration solves for numbers that its own data must be able to see. Zhang's equations see K but not the board size, so only a measured length checks the scale. Hand-eye sees the rotation after two axes of turning and the lever arm only after real turns. The time offset shows only while the image moves at changing rates. A running robot names its faults by regressing residuals on their covariates, and still needs one external length.
| Calibration | Needs | Blind when | Check it with |
|---|---|---|---|
| Intrinsics (Zhang) | 3 or more views, tilted 20°+ about changing axes | face-on or one tilt axis; corners never reached | fifth singular value of V; per-intrinsic spread; a coverage plot |
| Board scale | the true square size | always, to every residual | a measured bar: 1.000 m must read 1.000 m |
| Extrinsic rotation | turns about 2 non-parallel axes | yaw only (a ground robot) | second singular value of M |
| Lever arm | 30°+ of turn per motion | straight driving | smallest singular value of the stacked (RA − I) |
| Time offset | image motion that changes rate and sign | standing still; a steady turn | its spread, with its correlation to the gyro bias |
| In service | features across depth, radius and speed | no intercept; no range diversity | the four-term regression, |t| > 5 |
python import numpy as np def v_ij(H, i, j): """Zhang's row: v_ij . b == h_i^T B h_j, with b = [B11, B12, B22, B13, B23, B33].""" return np.array([H[0,i]*H[0,j], H[0,i]*H[1,j] + H[1,i]*H[0,j], H[1,i]*H[1,j], H[2,i]*H[0,j] + H[0,i]*H[2,j], H[2,i]*H[1,j] + H[1,i]*H[2,j], H[2,i]*H[2,j]]) def zhang_rows(H): """Two rows per view: r1 and r2 orthogonal, and equal in length.""" return [v_ij(H, 0, 1), v_ij(H, 0, 0) - v_ij(H, 1, 1)] def board_translation(K, H): """t = K^-1 h3 / |K^-1 h1|: the only metric output, and the only place the board size lands.""" Ki = np.linalg.inv(K) return Ki @ H[:, 2] / np.linalg.norm(Ki @ H[:, 0]) def handeye_rotation(a_list, b_list): """Procrustes on rotation vectors: find R with a_i = R b_i. Returns R and the singular values.""" M = sum(np.outer(a, b) for a, b in zip(a_list, b_list)) U, S, Vt = np.linalg.svd(M) return U @ np.diag([1.0, 1.0, np.linalg.det(U @ Vt)]) @ Vt, S def lever_arm(RA_list, tA_list, tB_list, RX): """Stack (R_A - I) t_X = R_X t_B - t_A. Returns t_X and the smallest singular value (the turn check).""" A = np.vstack([RA - np.eye(3) for RA in RA_list]) b = np.concatenate([RX @ tB - tA for tA, tB in zip(tA_list, tB_list)]) return np.linalg.lstsq(A, b, rcond=None)[0], np.linalg.svd(A, compute_uv=False)[-1] def td_bound(sigma_px, n_features, u_dot): """Best possible spread of the time offset, in seconds.""" return sigma_px / (np.sqrt(n_features) * u_dot) def calibration_monitor(res, inv_z, u_dot, r_px, f): """Regress residuals on [1, 1/Z, u_dot, r^3/f^2]. Returns yaw (rad), lever (m), t_d (s), dk1, and t-statistics.""" X = np.column_stack([np.ones_like(res), inv_z, u_dot, r_px ** 3 / f ** 2]) beta = np.linalg.lstsq(X, res, rcond=None)[0] s2 = np.sum((res - X @ beta) ** 2) / (len(res) - 4) tstat = beta / np.sqrt(np.diag(s2 * np.linalg.inv(X.T @ X))) return beta[0] / f, beta[1] / f, beta[2], beta[3], tstat
We ran every function above in NumPy on this lesson's examples. board_translation scales by exactly 0.920 under the typo. handeye_rotation recovers X to 10⁻¹⁴ degrees from five motions. lever_arm returns (0.30, 0.10) on Chapter 6's floor example. td_bound(0.3, 200, 240) gives 88 µs, and the monitor names each injected fault with |t| above 25.
Where it sits. A production robot calibrates intrinsics on a bench, extrinsics and the time offset in one recorded session (Kalibr, or OpenCV's calibrateHandEye for an arm), then watches residuals in service. Lesson 6 builds the front end that consumes these numbers; a wrong one shows up there as drift that no tuning removes.
Now teach it: press Present or Teach and explain why a wrong square size leaves K and the residual untouched but shrinks every depth. Then go back to the grasp and predict the miss at 27 mm before you drag there.