Skip to content

VisionFrom Pixels to Steering

The Pinhole Camera

Image size in pixels = f × real size ÷ distance, so a known size gives the distance.

Not started Jump to practice

A camera squashes the 3-D world onto a flat image. A simple model tells us exactly how, and lets a robot measure distance with one camera.

Key idea

In the pinhole model, an object of height $H$ at distance $Z$ makes an image $h = \dfrac{f\,H}{Z}$ pixels tall, where $f$ is the focal length measured in pixels. Know the object's real size, and $Z = \dfrac{f\,H}{h}$.
Move the object closer or farther, or make it bigger. The image size changes as $f H / Z$.

Why it works

Light from the top and bottom of the object passes through the pinhole and makes two similar triangles, one outside the camera and one inside. Similar triangles have equal ratios: $h/f = H/Z$. The Math Ladder's similar-triangles topic is all you need.

Worked example: How far?

A 0.2 m ball looks 50 pixels wide, with $f = 600$.
  1. $Z = 600 \times 0.2 / 50 = 2.4\ \text{m}$.

Answer: 2.4 m.

Common mistake

Mixing units: the focal length is in pixels, and the size and distance must both be in meters (or both in centimeters).
Real lenses bend straight lines a little; camera calibration measures $f$ and that bending from photos of a checkerboard.

Practice

Pass with 3 right answers, the last 2 in a row. Each right answer earns 3 XP.

Loading practice…

Builds on

Leads to

This is one of the top rungs of Robot Vision.

Sources and further reading