EN
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