Two cameras stand side by side, baseline metres apart, both looking straight ahead with the same lens f (the pinhole cameras from “Far looks smaller”). The same point lands x_left pixels right of the middle of the left camera’s photo and x_right pixels right of the middle of the right camera’s. Write depth(x_left, x_right, f, baseline): how many metres ahead is the point?
The avenue from “Far looks smaller”, photographed by two cameras 1 m apart. One photo alone only says which way a tree is, not how far. The two cameras’ lines cross at the tree, and on the photos that shows up as a shift between them. Your depth says how far ahead a point is from where it lands on both photos.
depth(x_left, x_right, f, baseline)| x_left | where the point lands on the left camera's photo, in pixels right of its middle | e.g. 250 |
| x_right | where it lands on the right camera's photo, in pixels right of its middle | e.g. 150 |
| f | both cameras' focal length (how far the photo is from the pinhole), in pixels | e.g. 400 |
| baseline | how far apart the two cameras are, in metres | e.g. 1 |
| returns | how many metres ahead of the cameras the point is | |