Stereo depth & triangulation
Before we begin
Lesson 2 matched points between views. With two calibrated cameras (or one moving camera), those matches become depth — how far each point is from the camera.
This lesson covers rectified stereo, disparity, and triangulation.
Learning objectives
- Define disparity and relate it to depth.
- Explain rectification and why search becomes 1D.
- Triangulate a 3D point from two views.
- Name failure modes: textureless regions, occlusions, reflective surfaces.
Disparity and depth
For a horizontal baseline setup (cameras side by side), a scene point projects to in the left image and in the right. Disparity (sign convention varies).
With focal length (pixels) and baseline (meters):
Smaller disparity → farther away. Points at infinity have .
Rectified stereo
General stereo has matches along epipolar lines. Rectification warps both images so epipolar lines are horizontal rows — for each row, search disparity along columns only.
OpenCV: cv2.stereoRectify + cv2.remap using calibration from Lesson 1.
Matching cost
For each pixel (or patch), compare left patch to right patch at candidate disparities. Pick disparity minimizing SAD, SSD, or normalized cross-correlation.
Semi-global matching (SGM) adds smoothness — popular in robotics and automotive.
Triangulation
Given two camera projection matrices , and matching pixels, solve for 3D point minimizing reprojection error (DLT or cv2.triangulatePoints).
Noise in pixel location → depth uncertainty grows with distance and narrow baseline.
Failure modes
| Issue | Effect |
|---|---|
| Textureless wall | Ambiguous matches — wrong depth |
| Occlusion | Visible in one view only — no match |
| Specular highlights | Appearance changes between views |
| Wide baseline | More precision but more occluded pixels |
Checkpoint
If baseline doubles and focal length stays fixed, what happens to disparity for the same scene point at fixed depth?
Answer sketch: Disparity doubles — same depth gives larger pixel shift; depth formula unchanged if you measure d correctly.