Two-View Geometry

Two photos and a set of matched pixels tell you how the camera turned and which way it moved. Here camera 2 stepped 1 m and turned 10° left. From 37 matches with 0.5 px of noise, the 8-point algorithm finds a 9.7° turn and the direction of the step within 0.2°. From only 8 matches with the same noise, it finds 1.6°. No number of matches gives the length of the step.

Pick 8 matches, then 37. Raise the noise. Then make the whole street ten times bigger and watch the pixels. Then we build it piece by piece: epipolar lines, the matrices E and F, the 8-point algorithm, the four poses, triangulation and the traps.

You need Lecture 5 (pixels, K and normalised coordinates), Lecture 1 (rotations and the cross product), a matrix times a vector and a little Python. We build the rest from zero.

Lecture 7 of 14 in our follow-along of MIT 16.485, Visual Navigation for Autonomous Vehicles (VNAV, taught by Luca Carlone). Every idea is re-taught here in our own words and devices. Previous: Lecture 6, feature detection and tracking. Next: Lecture 8, RANSAC.

Recover the motion from matches

0.5 px
×1.0

Illustrative toy street: 40 points 4 to 12 m away; 37 land in both 640 × 480 images. K has a focal length of 800 px. Real normalised 8-point algorithm and pose recovery run in your browser; OpenCV's findFundamentalMat and recoverPose give the same pose on the same pixels. We draw the recovered step at the true length so you can compare its direction.

Chapter 0

The Two-Photo Problem

Guess how camera 2 turned and watch the pairs of rays meet or miss

A drone takes two photos of a street from two places. Lecture 6 found the same corners in both photos: a set of matches, pairs of pixels that show the same scene point. Now we want two things. How did the camera move between the photos? And where is each matched point in 3D?

One photo cannot say. Lecture 5 showed that a pixel is a whole ray: every point along it lands on the same pixel. A match gives two rays, one from each camera. They meet at the scene point. But to draw the second ray in the first camera's frame, you must know how camera 2 stands relative to camera 1. That is the unknown.

So guess the pose and test the guess. If the guess is right, every pair of rays meets. If it is wrong, most pairs miss each other in 3D. Try it.

Guess the turn

Top view. Camera 2 stands 0.6 m right and 0.8 m ahead of camera 1, at its true place. Its six blue pixels are fixed. Slide your guess of its turn. Yellow bars below are the gaps between each pair of rays.

0.0°

Illustrative toy street; the truth is a 10° turn. The gap is the shortest distance between the two rays in 3D. A red gap label marks a pair that meets behind a camera.

At a guess of 4°, the six ray pairs miss each other by 4 to 39 cm, and every one meets behind a camera. At the true 10°, all six gaps close to zero, and the meeting points sit on the pink truth. The pose is hidden in the matches. This lecture finds it without guessing, from one equation per match.

Recovering the motion and the 3D points from images is called structure from motion. The two-view version has two steps. First, find the camera motion from the matches (Chapters 1 to 6). Then intersect the rays (Chapter 7).

Symptom: a 3D map from two photos has points behind the camera, or points that drift as you add matches.

Measure: the gap between each pair of rays under your pose. A right pose closes them all to the level of pixel noise.

Fix: do not guess the pose. Solve for it from the matches (Chapter 5), then check it (Chapter 6).

The road

  1. Epipolar geometry: a match must lie on one line.
  2. The constraint: that line as one equation per match.
  3. The essential matrix: E holds the turn and the direction of the step.
  4. The fundamental matrix: the same in pixels, with K folded in.
  5. The 8-point algorithm: solve for E from matches (the hero's solver).
  6. Four poses: one E gives four poses; pick the one in front.
  7. Triangulation: intersect the rays (the hero's purple points).
  8. Limits: scale, pure rotation and the flat wall.
  9. Showcase: the whole pipeline, and how to break it.
  10. Field guide: the formulas, the code and the credit.
You have one pixel in one calibrated camera. What do you know about the scene point?

Chapter 1

Epipolar Geometry: The Match Lies on a Line

Slide a point along camera 1's ray and watch its image in camera 2 trace a line

Pick a pixel in image 1 and slide its scene point along the ray, from near to far. In image 1 it never moves. In image 2 it traces a straight line.

So the match for that pixel must lie on that line. Search the line, not the whole image.

Slide a point along its ray

Choose how camera 2 moved. Slide the depth of the point. Tap image 1 to choose one of three pixels. Purple lines in image 2 are the three epipolar lines.

5.0 m

Exact maths, K with a focal length of 800 px and centre (320, 240). We draw image 2 with a margin so you can see where the lines head.

Why a line? Camera centre 1, camera centre 2 and the scene point form a triangle. That triangle lies in one plane, the epipolar plane. Slide the point along ray 1 and the plane does not change, because it always contains ray 1 and both centres. A plane cuts image 2 in a line: the epipolar line.

The line through both camera centres is the baseline. Every epipolar plane contains it, so every epipolar line in image 2 passes through one point: the image of camera 1's centre, called the epipole. In the running example the epipole of image 2 is at (1174, 240), off the right edge of a 640-pixel image. Step straight ahead and it moves to the centre (320, 240): the lines fan out from it. Step sideways with no turn and the epipole goes to infinity: every line is a horizontal row.

With numbers: pixel (400, 176) in image 1. At depth 2 m its image in camera 2 is (201.4, 137.7); at 5 m, (441.5, 163.0); at 30 m, (529.9, 172.3). All three sit on one line. Dense stereo uses the sideways case: it searches one row per pixel, not the whole image.

Symptom: a matcher pairs a corner with a look-alike corner far from where it should be.

Measure: the distance from the match to its epipolar line. A right match sits within a pixel or two of it.

Fix: once you know the epipolar geometry, search along the line only, and reject matches far from it (RANSAC does this in Lecture 8).

Camera 2 is camera 1 moved sideways, with no turn. Where are the epipoles?

Chapter 2

The Epipolar Constraint

Drag a candidate match off its line and watch one number leave zero

Now we write the line as one equation. Work in normalised coordinates from Lecture 5: undo K, so a pixel becomes the ray direction (xn, yn, 1). Call the match's ray in camera 1 y1 and in camera 2 y2.

Call the pose R and t: they map camera-1 numbers to camera-2 numbers, p2 = R p1 + t. In series notation they are RC2C1 and tC2C1, like RCW and tCW in Lecture 5. So t is camera 1's centre seen from camera 2.

Call the unknown depths along the two rays λ1 and λ2. The point is λ1y1 in camera 1 and λ2y2 in camera 2:

λ2 y2 = λ1 R y1 + t

Cross both sides with t. The term t × t is zero, so t drops out. We write "t cross" as the matrix [t]×, "t-cross", the hat operator of Lecture 1. Its rows are (0, −tz, ty), (tz, 0, −tx) and (−ty, tx, 0).

λ2 [t]× y2 = λ1 [t]× R y1

Now take the dot product of both sides with y2. On the left, t × y2 is at right angles to y2, so the left side is zero. Divide out λ1, and the constraint stays.

Say it aloud

y-two transposed, times t-cross, times R, times y-one, equals zero.

y2⊤
y-two transposed the match in camera 2 as a normalised ray (xn, yn, 1), written as a row.
[t]×
t-cross the 3 × 3 matrix that does "t cross" a vector. t is camera 1's centre seen from camera 2.
R
R the rotation that turns camera-1 directions into camera-2 directions.
y1
y-one the match in camera 1 as a normalised ray.
In plain words

Turn ray y-one into camera 2's frame with R. Cross it with t: that gives the normal of the epipolar plane. Take its dot product with y-two. If y-two lies in the plane, the answer is zero.

With numbers

The running example: camera 2 stands 0.6 m right and 0.8 m ahead and turned 10° left, so t = (−0.730, 0, −0.684). The point (0.5, −0.4, 5) gives y1 = (0.1, −0.08, 1) and y2 = (0.1519, −0.0963, 1). The plane normal [t]×R y1 is (−0.0547, 0.520, 0.0584), and y2 dotted with it is 0.0000. Move the match 10 px down and the result is 0.0065.

Test a match

The blue pixel in image 1 is fixed. Drag the blue ring in image 2, or use the buttons. The pink ring is the true match.

The running example, exact maths. The residual has no unit; the distance in pixels comes from the fundamental matrix of Chapter 4.

Slide the candidate along the line: the residual stays at zero. The constraint holds no depth, so it only says "on the line or not".

Symptom: a wrong match passes the test.

Measure: its distance to the epipolar line. A wrong match that happens to sit on the line gives a zero residual.

Fix: use many matches and let RANSAC find the pose most of them agree on.

In the derivation, why does the left side, y2⊤[t]×y2, vanish?

Chapter 3

The Essential Matrix

Turn and move camera 2 and watch E change while its singular values keep their shape

The middle of the constraint, [t]×R, does not depend on the match. It is one 3 × 3 matrix for the whole pair of images. Name it the essential matrix, E. Then every match must satisfy y2⊤ E y1 = 0. Longuet-Higgins introduced it in 1981.

Say it aloud

E equals t-cross times R.

E
E the essential matrix: 3 × 3, one for the pair of views. It maps a ray in image 1 to its epipolar line in image 2.
[t]×
t-cross the cross matrix of t, camera 1's centre seen from camera 2.
R
R the rotation from camera-1 directions to camera-2 directions.
In plain words

Build the cross matrix of t. Multiply it by R. E y-one is then the normal of the epipolar plane, written in camera 2: the epipolar line of y-one.

With numbers

The running example gives E with rows (0, 0.684, 0), (−0.8, 0, 0.6), (0, −0.730, 0). A sideways step of 1 m has t = (−1, 0, 0). Then E has rows (0, 0, 0), (0, 0, 1), (0, −1, 0), and y2⊤E y1 = yn,2 − yn,1: zero when both rows match.

Build E

Turn camera 2, aim its step, and change the step length. Watch the nine numbers of E, its three singular values, and the epipolar lines of three pixels.

10°
37° right
1.00 m

Exact maths. We measure the step direction from straight ahead, toward the right; 37° is the running example's (0.6, 0, 0.8).

Three facts show on the bars. First, E always has rank 2: one singular value is zero. The reason: E sends the direction of camera 2's centre to zero, because every epipolar plane contains the baseline. In the running example E times (0.6, 0, 0.8) is (0, 0, 0), and that direction points at the epipole of image 1, (920, 240).

Second, the two other singular values are equal, both the step length. Any matrix of the form [t]×R has singular values (|t|, |t|, 0). We use this later to clean up a noisy E.

Third, double the step and E doubles, but every line stays put: 2 × 0 is still 0. So E fixes the turn (3 numbers) and the direction of the step (2 numbers), not its length. E has 5 degrees of freedom. Set the step length to zero and E becomes all zeros: a pure turn tells E nothing (Chapter 8).

Symptom: a matrix from a solver has singular values (8.4, 3.1, 0.7) and the recovered pose wobbles.

Measure: its three singular values. A real E has (s, s, 0).

Fix: keep the singular vectors and set the values to (s, s, 0), with s the mean of the top two. That is the nearest real E.

Why does E have exactly one zero singular value?

Chapter 4

The Fundamental Matrix: Pixels Without K

Tap a pixel and watch F draw its line in the other image, then break K and watch it miss

E works on normalised rays, but a tracker hands you pixels. From Lecture 5, the homogeneous pixel ũ = (u, v, 1) gives y = K−1ũ. Put that into the constraint and K moves into the middle: the fundamental matrix F, with ũ2⊤ F ũ1 = 0.

Say it aloud

F equals K-two inverse transposed, times E, times K-one inverse.

F
F the fundamental matrix: 3 × 3, rank 2, works on pixels.
K2−⊤
K-two inverse transposed undoes camera 2's intrinsics on the side of image 2.
E
E the essential matrix of Chapter 3.
K1−1
K-one inverse turns a pixel of image 1 into its normalised ray. One moving camera has K1 = K2 = K.
In plain words

Turn the pixel of image 1 into a ray with K-one inverse. Apply E to get the epipolar line in normalised units. Bring that line into pixels with K-two inverse transposed. F does all three at once.

With numbers

The sideways step, with f = 800 px and centre (320, 240): F = (1/800) × rows (0, 0, 0), (0, 0, 1), (0, −1, 0). For the pixel (400, 300), Fũ1 = (0, 0.00125, −0.375): the line v = 300. The match keeps its row.

F turns a pixel into a line, l2 = Fũ1 = (a, b, c): all pixels with au + bv + c = 0. Then we can measure a match's distance from it in pixels.

Say it aloud

d equals the absolute value of l-two transposed times u-two-tilde, over the square root of a squared plus b squared.

d
d the distance from the match to its epipolar line, in pixels.
l2
l-two the epipolar line Fũ1 = (a, b, c).
ũ2
u-two-tilde the match in image 2 as (u, v, 1).
a² + b²
a squared plus b squared scales the line so the answer comes out in pixels.
In plain words

Put the match's u and v into the line: a u plus b v plus c. Divide by the length of (a, b). That is the gap d in pixels.

With numbers

The running example: for pixel (400, 176), the scaled line is (−0.1046, 0.9945, −115.88). The true match (441.50, 162.96) gives −46.18 + 162.06 − 115.88 = 0.00, so d = 0. Ten pixels lower, d = 9.95 px, almost 10 because the line runs nearly level.

Turn a pixel into a line

Tap a blue pixel in image 1. F draws its purple line in image 2. Then give F the wrong K and watch the line miss the pink match.

The running example with the 37 toy matches, no noise. The wrong F uses the true E with the wrong K.

With the right K every match sits on its line. With a focal length 10% low, the median match is 0.75 px off and the worst 1.6 px. That is enough to blur a RANSAC threshold. E on raw pixels gives a median of 17.9 px and a worst of 64 px.

F has 9 numbers, a free scale and a zero determinant: 7 degrees of freedom. With K you get E back as E = K2⊤ F K1. Without K, F still gives the lines, but not the turn and the step.

Symptom: the pose from a "calibrated" pipeline is off by degrees, though the matches look clean.

Measure: the median distance from each match to its epipolar line under your F.

Fix: recalibrate K (Lecture 5), or estimate F from the pixels directly and convert with the right K.

You estimated F from pixel matches. A friend says "now read off R and t". What is missing?

Chapter 5

The 8-Point Algorithm

Stack one row per match, solve the stack, and watch normalisation rescue the answer from noise

Now run the constraint backwards: we have the matches and want F. Written out, ũ2⊤Fũ1 = 0 is a sum of nine terms, each one entry of F times known pixel numbers. So each match gives one linear equation. Stack the nine entries of F row by row into a vector f.

Say it aloud

a-k transposed times f equals zero, where a-k is u-two u-one, u-two v-one, u-two, v-two u-one, v-two v-one, v-two, u-one, v-one, one.

ak
a-k the row for match number k: nine products of its pixel numbers.
f
f the nine entries of F read row by row: F11, F12, F13, F21, and so on.
In plain words

Multiply each match's pixel numbers pairwise into its row a-k. Stack the rows into a matrix A. Find the f of length 1 that makes A f closest to zero, and fold it back into F.

With numbers

With made-up numbers: the match (100, 200) to (95, 198) gives the row (9,500, 19,000, 95, 19,800, 39,600, 198, 100, 200, 1). The entries run from 1 to 39,600.

F has 8 free numbers once we fix its scale, so 8 matches pin it down. With noise, no f makes every row zero. The best f of length 1 is the last right singular vector of A, the direction A shrinks most. It gives a 3 × 3 matrix of rank 3, so set its smallest singular value to zero: the nearest rank-2 matrix.

The spread of 1 to 39,600 is the trap: it ruins the conditioning of A, so one pixel of noise moves the answer far. Hartley's fix (1997) is a normalisation. In each image, shift the points so their centroid is at the origin, and scale them to a mean distance of √2. Write that as a 3 × 3 matrix T, solve on the moved points, then undo the move.

Say it aloud

F equals T-two transposed, times F-hat, times T-one.

F
F the fundamental matrix for the original pixels.
T2⊤
T-two transposed image 2's normalising move, transposed.
F̂
F-hat the answer of the 8-point algorithm on the normalised points, rank 2.
T1
T-one image 1's normalising move: subtract the centroid, multiply by s = √2 over the mean distance.
In plain words

Move each image's points with its own T. Run the 8-point steps on the moved points to get F-hat. F-hat expects moved points, so wrap it in T-two transposed and T-one to get F for the original pixels.

With numbers

With made-up numbers: the points (100, 200), (300, 150), (500, 400), (200, 420) have centroid (275, 292.5) and mean distance 184.98 px, so s = 0.00765. The point (100, 200) moves to (−1.34, −0.71). Every entry of the new rows is now near 1.

Run the 8-point algorithm

Left: the nine singular values of A. Right: each match and its purple epipolar line. Raise the noise, then switch normalisation off.

1.0 px

The toy street, Gaussian pixel noise from a fixed seed. Our F matches OpenCV's findFundamentalMat (FM_8POINT, which normalises) to 1e−8 on the same pixels.

With 20 matches and 1 px of noise, normalisation gives a median line distance of 0.71 px and a step direction 2.3° off. Raw pixels give 3.02 px and 9.4°. The ratio of the largest to the eighth singular value of A drops from 134,000 to 42.

Five matches are enough. E has 5 degrees of freedom. The 8-point algorithm needs 8 because it fits a general 3 × 3 matrix first. Nistér's five-point solver (2004) uses the full structure of E and ends in a tenth-degree polynomial, so it returns up to ten candidate E. OpenCV's findEssentialMat runs it inside RANSAC.

Symptom: the 8-point result swings wildly between runs on the same scene.

Measure: the ratio of the largest to the eighth singular value of A. In raw pixels it can pass 100,000.

Fix: normalise each image first, and enforce rank 2 before you undo the normalisation.

The linear step returns a 3 × 3 matrix with singular values (8.4, 3.1, 0.7). What do you do before using it as F?

Chapter 6

Four Poses from E, and the Cheirality Check

Try each of the four poses hidden in E and count the points that land in front of both cameras

To get R and t, take the SVD of E: E = U diag(1, 1, 0) V⊤, with E scaled so s = 1. Call the third column of U u3. E⊤ sends it to zero, so it points along t. Call W the 90° turn about the z axis, with rows (0, −1, 0), (1, 0, 0), (0, 0, 1).

Say it aloud

R equals U W V-transposed, or U W-transposed V-transposed; and t equals plus or minus u-three.

R
R a candidate rotation from camera 1 to camera 2.
U
U the left singular vectors of E, flipped if needed so its determinant is +1.
W
W a 90° turn about z. W-transposed is the turn the other way.
V⊤
V-transposed the right singular vectors of E, also with determinant +1.
t
t the step direction, length 1.
u3
u-three the third column of U: the direction of the baseline, sign unknown.
In plain words

Take the SVD of E. Make U and V proper rotations. Build two rotations, one with W and one with W-transposed. Pair each with plus u-three and with minus u-three. That makes four poses, and every one gives the same E up to sign.

With numbers

The running example: u3 = (0.730, 0, 0.684), so t is ±u3; the true t is −u3. One rotation is the true 10° turn. The other is a 180° turn about the baseline. OpenCV's decomposeEssentialMat returns the same two rotations and the same u3.

Which one is real? Triangulate a match under each pose. A real point lies in front of both cameras, so both depths λ1 and λ2 are positive. This is the cheirality check. For the point (0.5, −0.4, 5), the four poses give depths (5.00, 4.15), (−5.00, −4.15), (0.66, −0.55) and (−0.66, 0.55). Only the first is in front of both.

Pick one of four

Each button is one of the four poses from E. The purple camera is camera 2 under that pose. A purple ring is a point in front of both cameras; a red cross is behind one.

The running example, 20 toy matches, no noise, E from the 8-point algorithm. The order of the four depends on the signs the SVD picks; the right one is the one with every point in front.

Flipping the sign of t moves camera 2 to the other side of camera 1, so the points land behind both cameras. Swapping W for W⊤ twists camera 2 by 180° about the baseline: in front of one camera, behind the other. One match decides in theory, but noise can flip a far point, so count over all matches.

Symptom: the recovered camera faces backwards, or the drone "flies" the wrong way.

Measure: the count of matches with both depths positive under the chosen pose.

Fix: test all four poses and keep the one with the most points in front; OpenCV's recoverPose does this.

Under the four poses, a match triangulates with depths (−2, 3), (4, −1), (−3, −5) and (4, 3). Which pose is real?

Chapter 7

Triangulation: Two Rays, One Point

Shrink the baseline and watch a pixel of noise throw the depth far away

Now we know R and t, and want the point where each match's two rays meet. Go back to the first line of Chapter 2: the point is λ1y1 in camera 1 and λ2y2 in camera 2.

Say it aloud

Lambda-two y-two equals lambda-one R y-one, plus t.

λ2
lambda-two the unknown depth of the point in camera 2, in units of the step.
y2
y-two the normalised ray of the match in camera 2.
λ1
lambda-one the unknown depth in camera 1.
R
R the rotation from camera 1 to camera 2, now known.
y1
y-one the normalised ray of the match in camera 1.
t
t camera 1's centre seen from camera 2, now known up to scale.
In plain words

This is three equations in two unknowns, lambda-one and lambda-two. Put R y-one and minus y-two side by side as a 3 × 2 matrix and solve for the two depths by least squares. With noise the rays miss: take the point halfway between their closest points.

With numbers

The running example's match gives λ1 = 5.000 and λ2 = 4.154, so the point is 5.000 × (0.1, −0.08, 1) = (0.5, −0.4, 5). Move the match 1 px right in image 2: λ1 = 5.041, the rays miss by 0.5 mm, and the midpoint is (0.504, −0.404, 5.041).

The DLT (direct linear transform) is the other common method. It asks that each ray be parallel to the projected point, y × (P X) = 0, which gives four rows in X; an SVD solves them. OpenCV's triangulatePoints gives (0.5042, −0.4036, 5.0414) for the moved match: the midpoint to within 0.1 mm.

Triangulate with noise

Two cameras side by side look at a pink point straight ahead. Camera 2's pixel is off by the noise. Shrink the baseline and push the point away.

0.50 m
10.0 m
0.5 px

Exact maths for a sideways stereo pair with f = 800 px. The error moves camera 2's pixel toward the image centre, so the estimate lands too far.

Why does a short baseline hurt? For side-by-side cameras, a point at depth Z shifts by f b / Z pixels between the images: its disparity. Depth is f b over the disparity, so a small disparity error moves the depth by an amount that grows with Z squared.

Say it aloud

Delta Z is about Z squared times delta u, over f times b.

Z, δZ
Z, delta Z the depth of the point, and the error in it, in metres.
δu
delta u the error in the match, in pixels.
f
f the focal length in pixels.
b
b the baseline: the distance between the camera centres, in metres.
In plain words

Square the depth. Multiply by the pixel error. Divide by the focal length times the baseline. Twice as far means four times the error; twice the baseline halves it.

With numbers

With made-up numbers: Z = 10 m, δu = 0.5 px, f = 800 px, b = 0.5 m. δZ ≈ 100 × 0.5 / 400 = 0.125 m. The exact answer is 0.127 m: the disparity drops from 40 px to 39.5 px.

Symptom: a drone that moved 1 cm between frames reports a building 50 m away as anywhere from 30 m to 200 m.

Measure: the angle between the two rays. Below a degree or so, depth is guesswork.

Fix: triangulate across frames far enough apart, or use a stereo rig with a known baseline.

Two drones see the same building 30 m away with the same pixel noise. One moved 1 mm between frames, the other 1 m. How do their depth errors compare?

Chapter 8

What Two Views Cannot Tell You

Scale the world, stop the step, flatten the street, and watch the solver lose its single answer

Three things defeat two views. The first is scale. Make the street and the step ten times bigger: every ray keeps its direction, so every pixel stays put. The running example's match lands at (441.50, 162.96) either way. Two views give the shape and the step direction, with one unknown scale.

The second is pure rotation. If camera 2 only turns, t = 0 and E is all zeros. Both rays of a match start at the same centre, so they give no depth. Instead, one matrix maps every pixel to the other image, whatever its depth.

Say it aloud

u-two-tilde is proportional to K R K-inverse, times u-one-tilde.

ũ2
u-two-tilde the pixel in image 2 as (u, v, 1), up to a scale.
K R K−1
K R K-inverse a homography: a 3 × 3 matrix that maps pixels to pixels. Undo K, turn, redo K.
ũ1
u-one-tilde the pixel in image 1 as (u, v, 1).
In plain words

Turn the pixel into a ray with K-inverse. Rotate the ray with R. Turn it back into a pixel with K and divide by the third number. The depth never enters.

With numbers

The running example's 10° turn with no step: pixel (400, 176) maps to (545.03, 173.85). A point on that ray at 5 m and one at 50 m land on the same pixel.

The third is a flat scene, such as a wall. A plane also maps image 1 to image 2 by one homography. Then A of the 8-point algorithm loses rank: it has three zero singular values instead of one, so a whole family of F fits the matches perfectly.

Find what two views cannot see

Left: a top view of the scene. Right: the nine singular values of A from noise-free matches, on a log scale. Count the bars that fall to zero.

×1.0

The toy street and the running example's turn; the wall is the plane z = 6 + 0.3x. Values below 1e−12 of the largest count as zero. Scaling the world leaves every bar where it was.

What survives? In a pure turn, every E in the family still splits into the right R. On our street the 8-point algorithm finds the 10° turn exactly; its step and depths are noise. On the flat wall the turn comes out 7° wrong. OpenCV's five-point solver found the true pose from our 28 wall matches. On another plane, it returned a pose 8° off that fit all 40 matches: a plane can admit two answers.

Symptom: a drone hovering and yawing in place reports nonsense translation and a cloud of random depths.

Measure: the median disparity after undoing the turn, or how well a homography fits compared with F.

Fix: when a homography fits as well, use it for the turn and wait for a real step before you triangulate. Get metric scale from a stereo baseline or an IMU (Lecture 11).

A monocular drone with no IMU and no known objects chains two-view estimates between frames. What can it recover?

Chapter 9

Showcase: Two Views to a 3D Street

Run the whole pipeline and break it with noise, a short step, a pure turn and a flat wall

Here is the whole chain. The page projects the toy street into both images and adds pixel noise. Then it runs the real steps: normalised rays, the 8-point algorithm, the nearest E, the four poses and the cheirality vote, and triangulation. Two views give no scale, so the page applies the true step length before it draws. A drone would need a second sensor for that.

Try four things. Raise the noise to 1 px: the turn stays within a degree, but far points scatter in depth. Choose the short step: the direction of the step falls apart, because every ray pair is nearly parallel. Choose the pure turn: the turn survives and the points do not. Choose the flat wall: even the turn goes wrong.

Reconstruct the street

Left: top view, pink truth and purple reconstruction. Right: image 2 with the blue matches and, in purple, each reconstructed point projected back. Yellow lines are the gaps.

0.5 px
all

Illustrative toy street of 40 points, K with f = 800 px, Gaussian noise from a seed you can change. Depth error is the median over the matches, after we apply the true scale.

With 0.5 px of noise on the street, the turn comes out 0.3° off and the step direction 0.2° off, yet the median depth is 8% wrong. Small angle errors grow into large depth errors at 12 m. With the 10 cm step and the same noise, the step direction is 11° off and depths are 67% wrong. This is why real systems refine everything together afterwards (Lecture 9).

Chapter 10

Field Guide

Keep the formulas, the numbers and the code side by side

A match is two rays. They can meet only if the second lies in the plane through the first ray and both camera centres. That gives one equation per match, y2⊤E y1 = 0. E = [t]×R has rank 2, singular values (s, s, 0) and 5 degrees of freedom. In pixels the same test uses F = K2−⊤E K1−1.

The 8-point algorithm stacks one row per match, takes the last right singular vector, and forces rank 2, after Hartley's normalisation. E splits into four poses, and the cheirality check keeps the one with points in front. Triangulation intersects the rays. The scale never shows; a pure turn and a flat wall break the solver.

PieceFormulaNumber on this pageWatch out
Constrainty2⊤[t]×R y1 = 00.0000; 10 px off: 0.0065zero all along the line
Essential matrixE = [t]×Rrows (0, .684, 0), (−.8, 0, .6), (0, −.730, 0); σ (1, 1, 0)step length cancels
Fundamental matrixF = K2−⊤E K1−1sideways step: v = 300 for (400, 300)wrong K: lines miss
Line distance|l2⊤ũ2| / √(a² + b²)10 px down: 9.95 pxnot the Sampson distance
8-pointA f = 0, last right singular vector, rank 220 matches, 1 px: 0.71 px vs 3.02 px rawnormalise first
NormalisationF = T2⊤F̂T1conditioning 134,000 to 42mean distance √2
Pose from EU W V⊤ or U W⊤V⊤, t = ±u3depths (5.00, 4.15) only for the real posecount over all matches
Triangulationλ2y2 = λ1R y1 + t(0.5, −0.4, 5); 1 px off: 5.041parallel rays
Depth errorδZ ≈ Z²δu / (f b)0.125 m (exact 0.127)grows with Z squared
Pure turnũ2 ∝ K R K−1ũ1(400, 176) to (545.03, 173.85)E = 0, no depth

The conventions on this page

The core, as code

python
import numpy as np, cv2

def hartley(p):                                   # centroid to 0, mean distance sqrt(2)
    m = p.mean(0); s = np.sqrt(2) / np.linalg.norm(p - m, axis=1).mean()
    return np.array([[s, 0, -s*m[0]], [0, s, -s*m[1]], [0, 0, 1]])

def eight_point(p1, p2):                            # p1, p2: (N, 2) pixels, N >= 8
    T1, T2 = hartley(p1), hartley(p2)
    h = lambda p, T: (T @ np.c_[p, np.ones(len(p))].T).T
    q1, q2 = h(p1, T1), h(p2, T2)
    A = np.array([np.outer(b, a).ravel() for a, b in zip(q1, q2)])   # one row per match
    F = np.linalg.svd(A)[2][-1].reshape(3, 3)                     # last right singular vector
    U, s, Vt = np.linalg.svd(F); F = U @ np.diag([s[0], s[1], 0]) @ Vt  # force rank 2
    F = T2.T @ F @ T1
    return F / np.linalg.norm(F)

def pose_from_E(E, y1, y2):                        # y1, y2: (N, 3) normalised rays
    U, _, Vt = np.linalg.svd(E)
    if np.linalg.det(U) < 0: U[:, 2] *= -1
    if np.linalg.det(Vt) < 0: Vt[2] *= -1
    W = np.array([[0, -1, 0], [1, 0, 0], [0, 0, 1]])
    best = None
    for R in (U @ W @ Vt, U @ W.T @ Vt):
        for t in (U[:, 2], -U[:, 2]):
            n = 0
            for a, b in zip(y1, y2):                   # l2*b = l1*R*a + t, least squares
                l1, l2 = np.linalg.lstsq(np.c_[R @ a, -b], -t, rcond=None)[0]
                n += (l1 > 0) and (l2 > 0)                # cheirality
            if best is None or n > best[0]: best = (n, R, t)
    return best[1], best[2]

# the library versions, on (N, 2) float pixel arrays p1, p2 and the 3x3 K
F, _ = cv2.findFundamentalMat(p1, p2, cv2.FM_8POINT)
E, mask = cv2.findEssentialMat(p1, p2, K, method=cv2.RANSAC, threshold=1.0)   # five-point inside RANSAC
n, R, t, mask = cv2.recoverPose(E, p1, p2, K)                                  # four poses + cheirality
X = cv2.triangulatePoints(K @ np.eye(3, 4), K @ np.c_[R, t], p1.T, p2.T)       # DLT, homogeneous

Where it sits

Lecture 5 turned points into pixels and pixels into rays. Lecture 6 found the matches. This lecture turns matches into the turn, the step direction and a 3D sketch. Real matches include wrong ones, and one wrong row spoils A: Lecture 8 wraps the solver in RANSAC. Lecture 9 refines poses and points together by least squares.

Keep going

The takeaway. A match is two rays that must share a plane with the baseline: y2⊤E y1 = 0. Eight matches give E by one SVD, once you normalise. E splits into four poses, and only one puts the points in front of both cameras. You get the turn and the direction of the step, never its length.

Now press Present or Teach. Derive the epipolar constraint from λ2y2 = λ1R y1 + t. Say why E has singular values (s, s, 0) and 5 degrees of freedom. Explain why the 8-point algorithm needs normalisation, and how the cheirality check picks one of four poses. Then go back to the hero and say why 8 matches fail where 37 succeed, and why the world scale changes nothing.

Credit

VNAV Lecture 7: Two-View Geometry
MIT 16.485 VNAV · Previous: feature detection and tracking · Next: RANSAC · Back to Gleams