SensorsBasicstereodisparitycameradepth
Stereo depth
In 30 secondsTwo cameras set apart see the same object shifted; nearby things shift more. Depth comes from Z = f · B / d.
Also available in: Català · Castellano
The formula
Z = f · B / d
f: focal length, in pixels.B: baseline, the distance between the two cameras.d: disparity, how many pixels the object shifts between the two images.
Example: f = 700 px, B = 0.12 m, d = 20 px → Z = 700 · 0.12 / 20 = 4.2 m.
Consequences
- A wider baseline or closer objects → more disparity → more precise depth.
- Far away, the disparity is only a few pixels and a one-pixel error changes the distance a lot.
Stereo vs lidar
Lidar measures distance directly with light and works at night. Stereo calculates it by comparing two images: it’s cheap and gives colour, but depends on light and on there being texture.
Interactive demo
Related concepts
Sensors
Lidar and SLAM
Counting wheel turns accumulates error (drift). A lidar measures distances in many directions at once; SLAM builds the map and locates itself in it by aligning each scan, which corrects the drift.
Sensors
Ultrasonic distance sensor
It sends a pulse and measures how long the echo takes: d = c · t / 2. The speed of sound depends on temperature, so if you don't compensate for it the reading drifts.