Conceptintro
Depth from disparity
Also called stereo depth equation.
For a rectified pair with focal length f and baseline b, a point with disparity d has depth Z = f b / d, so depth error grows as the square of depth.
In a rectified stereo pair with focal length in pixels and baseline , a point with disparity has depth , and its other two coordinates follow from its pixel. This is triangulation in the simplest geometry, where the two rays lie in one plane with the baseline and meet at a point that two similar triangles give. The same formula shows the main limit of stereo: an error of pixels in disparity gives an error of about in depth, which grows as the square of the distance.
In plain words
Hold a finger close to your eyes and close one eye, then the other. The finger jumps a lot against the background. A far tree hardly jumps at all. The jump is the disparity, and it is large for near things and small for far things. With two cameras a known distance apart, the size of the jump gives the distance exactly: half the jump means twice the distance. But far things jump so little that a small error in measuring the jump gives a large error in the distance. So stereo measures near things well and far things poorly, and a wider gap between the cameras helps.
The idea
The formula. Put the first camera at the origin and the second at , both with intrinsic matrix with , principal point and the same rotation, as after rectification. A point has pixels
So , and
The units of are the units of . The pixel size cancels, because and are both in pixels. In homogeneous form, with
and the point is . OpenCV calls this matrix the reprojection matrix; with , the second row gets the factor . If the rectified cameras have different principal points and , replace by first.
The error. Differentiate :
So the absolute depth error grows as , and the relative error grows as . This is a theorem to first order in . The size of is an empirical fact about the matcher: a good subpixel refinement gets to a few tenths of a pixel on textured surfaces, and much worse on textureless ones.
Depth layers. A matcher that returns whole disparities can only give the depths , The gap between two layers is , the same law. Near points are in thin layers and far points in thick ones.
The range. A search over cannot find points nearer than . The far limit is set by the smallest disparity the matcher can tell from zero.
The bias. The map is convex for . So if the measured disparity is the true one plus zero mean noise of variance , the mean of the computed depth is larger than the true depth (Jensen's inequality), by about to second order. For small disparities, averaging depths is worse than averaging disparities and then converting.
The baseline. A larger or a larger gives a larger disparity for the same depth and so a smaller depth error. The price is a larger disparity range to search, more occlusion, and a larger change of view between the images, which makes matching harder. Okutomi and Kanade (1993) used several baselines at once to get both.
Examples
Check value. , m, gives m. With and the pixel , the point is m, m.
Error against depth. With , m and a disparity error of pixel:
| (m) | (pixels) | (m) | relative error |
|---|---|---|---|
| 1 | 50 | 0.005 | 0.5% |
| 2.5 | 20 | 0.031 | 1.25% |
| 5 | 10 | 0.125 | 2.5% |
| 10 | 5 | 0.5 | 5% |
| 25 | 2 | 3.1 | 12.5% |
At 25 m the disparity is 2 pixels, and a quarter pixel of error is already an eighth of it.
Depth layers. With the same rig, whole disparities 20 and 19 give 2.5 m and 2.632 m, a gap of 13 cm. Disparities 5 and 4 give 10 m and 12.5 m, a gap of 2.5 m.
Where it is used
- Stereo cameras. Robots, cars and drones turn each disparity map from stereo matching into a depth map and a point cloud with this formula. The law sets the useful range of a camera pair for a given baseline.
- Structured light. A projector and a camera form a rectified pair in the same way, and structured light scanning uses the same formula with the projector in place of the second camera.
- Fusion. Depth map fusion and TSDF fusion weight each depth by its expected error, which grows with .
- General triangulation. For cameras that are not rectified, the rays do not meet in general, and point triangulation finds the best point by least squares. The rectified formula is its special case.
References
- Richard Szeliski, Computer Vision, Algorithms and Applications, second edition, Springer, 2022, Chapter 12, Depth estimation (the relation between disparity and depth in a rectified pair)
- Daniel Scharstein and Richard Szeliski, A taxonomy and evaluation of dense two-frame stereo correspondence algorithms, International Journal of Computer Vision 47(1-3), 2002, 7-42, the part that relates disparity to inverse depth
- Richard Hartley and Andrew Zisserman, Multiple View Geometry in Computer Vision, second edition, Cambridge University Press, 2004, Chapter 12, Structure computation (triangulation of a point from two views, of which the rectified case is the simplest)
Where this leads
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag V59KRG Edit this page History Report an error Markdown