Search

Search papers and lessons

Triangulation

Level 3 · 14 min read

Triangulation recovers a 3D point from its pixel positions in two or more calibrated photos by intersecting the rays from each camera, solved as a small linear system.

On this page

  • Colour = topic mix
  • Linear algebra
  • Computer vision
  • Discrete math
  • Sign in to see your progress

TL;DR

A single photo tells you the direction to a point but not how far away it is. Take a second photo from another position and each camera gives you a ray toward the same point. Triangulation finds the 3D point where those rays meet. In practice the rays never cross exactly because pixels are noisy, so the method picks the point that best fits all the measurements, usually by solving a small linear system.

Where you'll see it: in stereo depth sensing on phones and cars, in 3D reconstruction from photo collections, and as the final step of structure from motion, where each new 3D point is placed by triangulating its matched pixels.

Intuition

Two rays that meet

Stand at two spots a few metres apart and look at the same lamp post. From each spot you can point in the direction of the lamp. Draw both pointing lines on a map and they cross at the lamp. Your two bearings fix its position, and the distance between your spots, called the baseline, sets how accurately you can locate it.

A camera does the same thing. A pinhole camera turns a 3D point into a pixel, and the set of 3D points that land on that pixel is a ray from the camera centre. Given two cameras whose positions and internal settings are known, a point seen in both images sits where the two rays intersect.

Why it is not just a crossing

Real pixels are measured with error, so the two rays miss each other in 3D. They pass close to each other near the true point but do not cross exactly. Triangulation has to pick one point. The usual answer is the point that best explains the measured pixels in both images, the one whose projections land closest to the observed positions. That turns a geometric question into a least-squares problem.

The same logic extends to many cameras. Each extra view adds rays, and the estimate becomes more stable. Stereo depth, which makes a depth map from two side-by-side cameras, is the same method applied to every pixel of the image.

flowchart LR
  A[Matched pixels in view 1 and view 2] --> B[Known camera matrices P1 and P2]
  B --> C[Linear equations for the 3D point X]
  C --> D[Solve with SVD]
  D --> E[Divide by last coordinate]
  E --> F[3D point X]

The math

Setup

Each calibrated camera is a 3×43 \times 4 matrix P=K[R∣t]P = K[R \mid \mathbf{t}] from the pinhole model, where KK holds the internal settings, RR is rotation and t\mathbf{t} is translation. A 3D point X=(X,Y,Z,1)⊤\mathbf{X} = (X, Y, Z, 1)^\top is written in homogeneous coordinates, and it projects to the image point x∼PX\mathbf{x} \sim P\mathbf{X}, where ∼\sim means equal up to a nonzero scale. In a pixel with coordinates (u,v)(u, v), the homogeneous image point is (u,v,1)⊤(u, v, 1)^\top.

Write p1,p2,p3\mathbf{p}^1, \mathbf{p}^2, \mathbf{p}^3 for the three rows of PP. Then PXP\mathbf{X} has entries p1X\mathbf{p}^1\mathbf{X}, p2X\mathbf{p}^2\mathbf{X} and p3X\mathbf{p}^3\mathbf{X}, and the projection to pixel coordinates is u=p1X/p3Xu = \mathbf{p}^1\mathbf{X} / \mathbf{p}^3\mathbf{X} and v=p2X/p3Xv = \mathbf{p}^2\mathbf{X} / \mathbf{p}^3\mathbf{X}.

Linear equations

Clear the denominator. Each observed pixel gives two equations that are linear in X\mathbf{X}:

u (p3X)−p1X=0,v (p3X)−p2X=0.u\,(\mathbf{p}^3\mathbf{X}) - \mathbf{p}^1\mathbf{X} = 0, \qquad v\,(\mathbf{p}^3\mathbf{X}) - \mathbf{p}^2\mathbf{X} = 0.

Each camera contributes two rows to a matrix AA, and the unknown is the 4-vector X\mathbf{X}. For two cameras you get a 4×44 \times 4 system AX=0A\mathbf{X} = \mathbf{0}. This is the direct linear transform (DLT). In the noise-free case the system has a nonzero solution, and that solution is the point. With noise it has no exact solution, so we look for the unit vector X\mathbf{X} that makes ∥AX∥\lVert A\mathbf{X}\rVert smallest.

Solving with SVD

The singular value decomposition writes A=UΣV⊤A = U\Sigma V^\top, where the singular values in Σ\Sigma are sorted from largest to smallest. The unit vector that minimises ∥AX∥\lVert A\mathbf{X}\rVert is the last column of VV, the one paired with the smallest singular value. Divide its first three entries by its fourth to get (X,Y,Z)(X, Y, Z) in the world frame.

Roughly, the smallest singular value (after scaling the rows sensibly) reflects how well the rays agree: a tiny value means they nearly meet, and a large one means the measurements conflict. It is an algebraic residual, not a distance in pixels, which is why the tradeoffs section recommends refinement.

Depth from disparity

For a rectified stereo pair with focal length ff and baseline bb, a point at depth ZZ shifts between the two images by a disparity d=fb/Zd = fb/Z. Depth is therefore Z=fb/dZ = fb/d. Nearby points have large disparity and far points have small disparity, and the error in ZZ grows quickly as dd shrinks.

Worked examples

Example
Two cameras, by hand

Use normalised cameras with K=IK = I. Camera 1 sits at the origin, so its coordinates are the world coordinates. Camera 2 is shifted by one unit along xx, so its camera coordinates are (X+1,Y,Z)(X+1, Y, Z). The true point is X=(2,1,4)\mathbf{X} = (2, 1, 4).

  1. Camera 1 sees u1=X/Z=2/4=0.5u_1 = X/Z = 2/4 = 0.5 and v1=Y/Z=1/4=0.25v_1 = Y/Z = 1/4 = 0.25.
  2. Camera 2 sees u2=(X+1)/Z=3/4=0.75u_2 = (X+1)/Z = 3/4 = 0.75 and v2=Y/Z=0.25v_2 = Y/Z = 0.25.
  3. From the first camera, X=0.5 ZX = 0.5\,Z and Y=0.25 ZY = 0.25\,Z. From the second, X+1=0.75 ZX + 1 = 0.75\,Z.
  4. Substitute X=0.5 ZX = 0.5\,Z into the second: 0.5 Z+1=0.75 Z0.5\,Z + 1 = 0.75\,Z, so 0.25 Z=10.25\,Z = 1 and Z=4Z = 4.
  5. Then X=2X = 2 and Y=1Y = 1, recovering X=(2,1,4)\mathbf{X} = (2, 1, 4) exactly.

With exact pixels this is just intersection. Note the disparity: ∣u1−u2∣=0.25=1/Z|u_1 - u_2| = 0.25 = 1/Z (the sign only reflects which way camera 2 is shifted), which matches the depth-from-disparity formula with f=b=1f = b = 1.

Example
Depth error from a small disparity change

Keep the same rig, f=1f = 1 and b=1b = 1, so Z=1/dZ = 1/d.

  1. A point at depth Z=4Z = 4 has disparity d=0.25d = 0.25.
  2. Suppose the pixel measurement is off by 0.01, so the measured disparity is 0.260.26. Then Z=1/0.26≈3.85Z = 1/0.26 \approx 3.85.
  3. Compare the error: the depth is off by about 0.150.15, which is about 3.8% of 4.
  4. Now take a far point at Z=20Z = 20, where d=0.05d = 0.05. The same measurement error of 0.01 gives d=0.06d = 0.06 and Z=16.7Z = 16.7, an error of 3.3 units, or 17% of the depth.
  5. Interpretation: the same pixel error costs far more depth accuracy at long range. A wider baseline makes disparities larger, which is why stereo rigs are spread apart for distant sensing.

The curve below shows how depth falls as disparity grows, with the near point from the examples (Z=4Z = 4, d=0.25d = 0.25) and two other points marked.

0.511.520246810disparity d (pixels, in these units)depth Z
  • Z = 1 / d
For f = b = 1, depth is one over disparity. The marked points are disparities 0.25, 0.5 and 1, giving depths 4, 2 and 1.

Tradeoffs and failure modes

Triangulation is only as good as the cameras and the matches behind it.

SituationWhat goes wrongBetter choice
Small baseline, distant pointsRays are nearly parallel, so depth is poorly determined.Widen the baseline, or use more views.
Wrong pixel matches between viewsOne bad match pulls the point far off.Reject outliers with a robust method such as RANSAC before triangulating.
Poor camera calibrationThe matrices PP are wrong, so every point is biased.Calibrate carefully, or refine the cameras jointly with the points.
Points behind a camera (Z≤0Z \le 0)The division flips sign and the result is meaningless.Check the sign of the depth and discard such points.
Plain linear (DLT) estimate with noiseThe linear solve minimises an algebraic error, not the pixel error.Refine with nonlinear least squares on the reprojection error.

The linear method is fast and makes a good starting point. The true objective is the distance between the projected point and the measured pixel in each image, and that is nonlinear in X\mathbf{X}. Refining with nonlinear least squares gives the optimal estimate, at a higher cost.

History

Triangulation is much older than computer vision. Surveyors used it for centuries to measure distances they could not reach, by sighting the same landmark from two known points. Stereo vision brought the same geometry to images in the 19th century, when stereoscopes let viewers fuse two photographs into one 3D scene.

In computer vision, the linear DLT approach was standard in the 1990s. In 1997 Richard Hartley and Peter Sturm analysed the optimal triangulation problem, showing that the best estimate minimises the pixel reprojection error and that the linear method can be improved considerably. Their work and the textbook by Hartley and Zisserman set the modern treatment, which is now the basis of structure from motion and multi-view reconstruction.

Check yourself

QuestionRecall: why does a single photo not determine a 3D point's position?Show answer
A single camera gives only the ray from its centre through the pixel. Every point along that ray projects to the same pixel, so the depth is unknown. A second view supplies a second ray, and the point is where the two rays meet.
QuestionComputation: a rectified stereo pair has f=2f = 2 and b=0.5b = 0.5. A point has disparity d=0.1d = 0.1. What is its depth?Show answer
Use Z=fb/d=2⋅0.5/0.1=10Z = fb/d = 2 \cdot 0.5 / 0.1 = 10. The depth is 10 units, in the same units as the baseline.
QuestionWhy: the two rays from a noisy pair of cameras do not intersect exactly. What should triangulation return instead?Show answer
It should return the point that best explains the measurements, normally the point that minimises the pixel reprojection error in every view. The linear DLT solve finds the point minimising an algebraic error, which is close to this and is a good starting point, and refinement with nonlinear least squares gives the optimal estimate.
QuestionApplied: a wide-baseline and a narrow-baseline rig both observe a distant building. Which one gives the more accurate depth, and why?Show answer
The wide-baseline rig. Its disparity is larger for the same depth, so a given pixel error changes the estimated depth by a smaller fraction. The narrow baseline produces nearly parallel rays for distant points, and depth error grows quickly with range.

Sources