Skip to content
Tactiverge

Cameras and depth sensing

How image sensors capture light, what frame rate and exposure mean for a moving robot, and how stereo, structured light and time of flight measure depth, and fail.

Lesson 4 of 6 · 35 min · Self-paced · Free

The richest sensor, and the hardest to use

A single camera image contains hundreds of thousands of measurements, enough to recognise objects, read labels and see where a path goes. That richness is why cameras are on almost every modern robot. But an ordinary image is flat: it tells you which direction something is in, not how far away. And cameras are surprisingly easy to fool with glare, darkness, motion or a plain white wall. This lesson covers how cameras capture images, how robots recover depth, and the specific ways each method fails.

Inside an image sensor

A camera's image sensor is a grid of tiny light-sensitive cells, one per pixel. During an exposure, each cell collects light and builds up an electrical charge proportional to how much light hit it. The charges are read out and converted to numbers, typically 0–255 for each pixel in an 8-bit image.

The cells themselves cannot tell colours apart. Most colour cameras place a mosaic of red, green and blue filters over the grid, commonly the Bayer pattern, and software estimates the full colour at each pixel from its neighbours.

The numbers add up quickly. A modest 640 × 480 image has 307,200 pixels. With three colour values per pixel at 30 frames per second, that is:

640 × 480 × 3 × 30 = 27,648,000 bytes per second ≈ 27.6 MB/s

That is a lot of data for a small robot computer to move and process, which is one reason robots often use lower resolutions than phones do.

Frame rate, exposure and motion

Frame rate is how many images per second the camera delivers. At 30 frames per second (fps), a new image arrives every 1/30 s ≈ 33 ms. Anything that happens between frames is invisible to the robot.

Exposure time is how long each cell collects light. Longer exposures gather more light and less noise, but anything that moves during the exposure is smeared, called motion blur. If an object moves at 0.5 m/s and the exposure lasts 10 ms:

blur = 0.5 m/s × 0.010 s = 0.005 m = 5 mm

In dim light the camera automatically lengthens its exposure, so blur gets worse exactly when the image is already poor.

Many inexpensive sensors use a rolling shutter: they read out the image row by row, so the top of the frame is captured slightly earlier than the bottom. A fast-moving object or a vibrating robot can appear tilted or wobbly. A global shutter captures every pixel at the same instant and is preferred for fast-moving robots, at higher cost.

Recovering depth

A single image loses distance information: a small cup nearby and a large cup far away can look identical. Robots recover depth in three main ways.

Stereo vision

Two cameras side by side, a known distance apart, see the same scene from slightly different positions, just like your two eyes. A nearby object appears in noticeably different places in the two images; a distant one barely shifts. That shift, measured in pixels, is the disparity d. For two parallel cameras with focal length f (in pixels) and separation, or baseline, B:

depth Z = f × B / d

With f = 700 pixels and B = 6 cm:

f = 700      # focal length in pixels
B = 6.0      # baseline in cm

for d in [84, 83, 21, 20, 7, 6]:
    Z = f * B / d
    print(f"disparity {d:2d} px  ->  depth {Z:6.1f} cm")
disparity 84 px  ->  depth   50.0 cm
disparity 83 px  ->  depth   50.6 cm
disparity 21 px  ->  depth  200.0 cm
disparity 20 px  ->  depth  210.0 cm
disparity  7 px  ->  depth  600.0 cm
disparity  6 px  ->  depth  700.0 cm

Look at what a one-pixel mistake costs. At 50 cm it shifts the depth by about 6 mm. At 2 m, by 10 cm. At 6 m, by a whole metre. Stereo depth error grows roughly with the square of distance, so stereo is precise up close and vague far away. A wider baseline helps, at the cost of a bulkier sensor.

Stereo also needs to match points between the two images. On a blank wall, a uniform floor or a repeating pattern like a fence, there is nothing distinctive to match, and stereo gives no answer or a wrong one.

Structured light

A structured-light sensor solves the matching problem by projecting its own pattern, often a field of infrared dots or stripes, and watching it with a camera offset to one side. Surfaces at different depths shift the pattern by different amounts, and the same triangulation geometry as stereo turns those shifts into depth. Because the sensor supplies its own texture, blank walls are no longer a problem.

Its weakness is that its pattern must be visible. Bright sunlight washes out a projected infrared pattern, so many structured-light sensors work well indoors and poorly outside. Very dark surfaces absorb the pattern, and mirrors or glass send it somewhere else.

Time of flight

A time-of-flight (ToF) sensor sends out light and measures how long it takes to return. Light travels about 30 cm per nanosecond, so the timing must be extraordinarily fine. For a target 1 m away, the round trip is 2 m:

time = 2 m / (3 × 10⁸ m/s) ≈ 6.67 ns

and resolving 1 cm of depth means resolving about 67 picoseconds of round-trip time. Many ToF cameras measure this indirectly, by modulating their light and measuring the shift in phase of the returning wave. Lidar, which sweeps laser beams around a scene, uses the same principle.

ToF sensors work on blank surfaces and give a depth for every pixel at once. Their typical failure is multipath: light that bounces off a second surface before returning takes longer, so corners and shiny floors can produce depths that are too long. Dark materials return little light, and transparent objects may be invisible altogether.

A catalogue of failure modes

It is worth collecting these together, because a robot must be designed around them:

  • Lighting: too dark (noise, blur), too bright (washed-out pattern), or backlit.
  • Texture: blank or repeating surfaces defeat stereo matching.
  • Material: glass and clear plastic are often invisible to depth sensors; mirrors and polished metal give false readings; black fabric absorbs light.
  • Motion: blur and rolling-shutter distortion.
  • Occlusion: a camera cannot see what is behind something, including the robot's own gripper.
  • Range: stereo degrades with distance; projected-light sensors have a limited maximum range.

None of this makes cameras bad sensors. It makes them sensors with known weaknesses, which is exactly why robots combine them with touch, force and motion sensing.

Recap

An image sensor counts light at each pixel during an exposure; frame rate sets how often the robot gets news, and exposure sets how blurred it is. Stereo infers depth from disparity, Z = f × B / d, precisely nearby and poorly far away. Structured light projects its own texture but struggles in sunlight. Time of flight times light's round trip but suffers from multipath. Each method has failure modes a robot designer must expect.

Knowledge check

Check your understanding

  1. 1. A camera exposes each frame for 20 ms while an object crosses the view at 0.25 m/s. How long is the motion blur?
  2. 2. A stereo camera has f = 500 pixels and baseline B = 10 cm. An object shows a disparity of 25 pixels. How far away is it?
  3. 3. Why does stereo depth estimation struggle with a plain white wall?
  4. 4. What is multipath error in a time-of-flight sensor?
  5. 5. A robot must detect clear glass bottles on a shelf. Which concern is most important?

Go further