Cameras — study guide
The concept's fragments, read in order.
For your capstone Fly a site and deliver a survey-grade map
The camera is the instrument the job is measured with: every one of the roughly 250 photos becomes a set of measurements of the ground. Gimbals and survey cameras and Camera geometry for mapping both start from its grid of photosites.
Its sensor has 5472 by 3648 photosites, about 20 million numbers a photo, each a count of light turned into an integer by a converter. A photo comes roughly every three seconds and is stored on the aircraft, so latency stops mattering and the instant of exposure matters more. A rolling readout of 30 to 40 milliseconds on a moving aircraft would take each row from a slightly different place, one reason the example job's camera has a mechanical shutter.
A grid of light meters
A camera hands a robot more information than any other sensor it carries, and asks more of the robot in return. Take the case off a camera module and there are three parts: a lens that gathers light from the scene, an image sensor that measures that light at hundreds of thousands or millions of points, and electronics that turn the measurements into numbers and send them down a wire. What comes out is not a picture in any sense a person would recognize. It is a stream of frames, and each frame is a grid of numbers, one or a few for every point the sensor measured.
Almost everything a builder needs to know about a camera is a property of that grid. How many numbers it holds is the resolution. How finely each number divides the span from dark to bright is the bit depth. How many grids arrive each second is the frame rate, and how old each one is by the time a program reads it is the latency. Multiply the size of one grid by the rate and the result is the data rate, which decides what kind of wire can carry the camera at all.
Two quite different machines rely on the same mechanism. A small self-driving car reads frames from a camera plugged into its single-board computer and has to turn them into steering decisions many times a second. A survey drone carries a much larger camera that takes one still photo every few seconds and keeps it, so the ground can be measured from it later. The sensor works the same way in both. What differs is which of its numbers matters most, and how it lets the robot down when that number is wrong.
From light to a number
An image sensor is a chip whose surface is a grid of tiny light-sensitive sites called photosites, usually just called pixels, and the grid works like a field of rain gauges set out in rows, each catching whatever falls on its own small patch for a fixed time and then read off as a number. While the exposure lasts, photons land on each photosite and some of them free electric charge, which collects there. When the exposure ends, that charge is turned into a voltage, amplified, and handed to an analog-to-digital converter, which turns it into an integer. EMVA 1288, the European Machine Vision Association's standard for characterizing image sensors and cameras, models that whole chain as linear: twice the light gives twice the number, until the photosite is full.
The converter is an ordinary ADC, so its bit depth means what it means anywhere else. An 8-bit value has 256 levels from black to full, a 10-bit value 1024, a 12-bit value 4096. The Linux kernel's camera interface defines raw sensor formats from 8 up to 16 bits per sample, and its common finished formats, such as RGB and YUYV, carry 8 bits, one byte, per value. Extra bits give finer steps between tones, which shows most where a scene is dim and all its useful values are squeezed into the bottom of the scale.
Resolution is the size of the grid, written width by height. A sensor read at 640 by 480 delivers 307,200 values per frame; 1920 by 1080 delivers about 2.07 million. A 20-megapixel survey camera with 5472 by 3648 photosites delivers about 20 million. More photosites resolve finer detail in the scene, and every one of them is a number that has to be moved, stored and looked at by a program, a cost that comes back in every later decision about a camera.
Color from a mosaic of filters
A photosite counts photons. It has no idea what color they were. A color camera with a single sensor gets color by laying a mosaic of tiny filters over the grid, one filter per photosite, each passing only red, green or blue light. The usual pattern was patented by Bryce Bayer in 1976 and still carries his name: in every two-by-two block there are two green filters on one diagonal and one red and one blue on the other. Half the sites are green because, in the patent's words, luminance detail is what the human eye is most responsive to, and the eye's sensitivity peaks in the green middle of the spectrum.
So the raw output of a color sensor holds one number per site, for one color. A 2005 review of the problem puts it plainly: the camera has to estimate the two missing color values at every pixel, a step called demosaicing. Each pixel borrows its missing red, green or blue from the neighbors that did measure them, much like working out the true colors of a scene seen through a window of small tinted panes, each pane showing only how much red, green or blue came through it, by looking at what the panes around it let through. The review also showed that ordinary smooth interpolation leaves visible artifacts, which is why demosaicing has a family of methods of its own that follow edges rather than blur across them.
The consequence for a builder is that a color frame contains less measurement than it appears to. A 640 by 480 frame stored as red, green and blue holds 921,600 numbers, but only 307,200 of them were measured; the rest are educated guesses. Where the guess goes wrong, at sharp high-contrast edges and fine repeating patterns, a program can see colored fringes that were never in the scene. A sensor with no color filter at all measures brightness at every site, and that is one reason a robot that only needs edges and shapes may be better served by a monochrome camera.
What the lens shows, and how long the sensor looks
The lens decides what the sensor sees. It bends the light from each direction in front of the camera onto one spot of the chip, so the scene lands on the sensor as a small, sharp image. The one number to know is the focal length: a shorter one squeezes a wider view onto the same chip, and a longer one sees a narrower slice, magnified. A robot car looking for the edges of a track wants the wide view; a camera meant to read a sign far ahead wants the narrow one. How much ground each pixel ends up covering is a matter of geometry, and camera geometry is where that is worked out.
Exposure is how much light each photosite gets to collect for one frame, and three things set it. The exposure time is how long the photosites collect. The aperture, the size of the opening in the lens, is how much light gets through in that time. The gain is how much the signal is amplified afterward, the setting a photographic camera calls ISO. The first two change how much light is actually caught; gain changes only how big the resulting number is.
That difference matters because of noise. Light arrives as photons at random, so a photosite's count scatters from frame to frame even under steady light, and EMVA 1288, the European Machine Vision Association's sensor standard, gives the size of that shot noise: its variance equals the count itself. A photosite that caught 100 electrons is uncertain by about 10, a tenth of its signal; one that caught 10,000 is uncertain by about 100, a hundredth. In dim light the counts are small and the image is grainy.
Gain cannot rescue it. The same standard notes that, apart from a small effect of rounding to whole numbers, the gain cancels out of the signal-to-noise ratio: amplifying a weak count multiplies the noise as much as the signal. The only cures are more light per frame, from a longer exposure, which smears anything that moves, or a wider aperture, or a brighter scene. How a moving survey camera trades those against each other belongs to exposure and motion blur; for a robot, the lesson is that a dark frame turned bright is still a dark frame.
Frames per second, and rows read in turn
A video camera repeats its measurement on a fixed beat, the frame rate. At 30 frames per second each frame has 33.3 milliseconds, at 60 only 16.7, and the exposure has to fit inside that slot. So in dim light a camera has two choices: keep its frame rate and deliver darker, noisier frames, or stretch the exposure and deliver fewer of them. Frame rate decides how often a robot looks at the world, and nothing between two frames is ever seen.
Once the photosites have collected their charge, the sensor has to read millions of them out through a limited number of converters, and it can arrange that in two ways. A global readout starts and stops every photosite's exposure at the same instant, so the whole frame is one moment, and the reading out happens afterward. A rolling readout resets and reads the sensor one row at a time, top to bottom. Every row gets the same exposure length, but each row's turn comes a little later than the row before it, like a crowd photographed by a camera that sweeps down a stadium one row of seats at a time, so a fan running down the aisle turns up in a different place in each row.
Rolling readout is the usual kind in the CMOS sensors of phones, action cameras and many consumer drones. A 2016 study of drone cameras explains why: a global shutter on a CMOS sensor needs more complex circuitry in each pixel. The same study puts a full rolling readout at about 30 to 40 milliseconds for most consumer cameras, which is about the longest that still allows video at 30 or 25 frames per second. In other words, on many cameras the last row of a frame is captured most of a frame period after the first.
That delay shows whenever something moves. With a 30-millisecond readout, an object crossing the view at 2 meters per second moves 6 centimeters between the top row and the bottom row, so an upright pole comes out leaning. When the camera itself turns or shakes, every row is taken from a slightly different viewpoint and the whole frame skews or wobbles. For a robot that only needs to find a line, this is a nuisance to know about; for a camera that measures, it is a source of error that survey payloads takes up in detail.
The image a program reads
To a program, a frame is a block of memory holding numbers in an agreed order. The Linux kernel's camera interface states the order for its standard uncompressed formats: pixels run left to right and top to bottom, and the first byte of the buffer belongs to the leftmost pixel of the top row. So a pixel is named by its row and column, counted from zero at the top-left corner, with rows counting downward. A program that puts the origin at the bottom left, the way a graph is drawn, reads the whole scene upside down.
What each pixel holds depends on the format. A grayscale frame stores one byte per pixel. A color frame in the common RGB layout stores three bytes per pixel, red, green and blue in that order, so in a frame w pixels wide with no padding, the pixel at row r and column c starts at byte (r * w + c) * 3. The same interface also defines BGR, the same three bytes with blue first, and a frame whose reds and blues look swapped is the usual sign of a program reading one as the other.
Other formats are leaner. YUYV stores a brightness value for every pixel but shares one pair of color values between two neighbors, two bytes per pixel, and a raw Bayer frame holds one sample per photosite. A JPEG frame is compressed and has to be decoded into one of these layouts before any of its pixels can be read. The interface also allows padding bytes at the end of each row to keep rows aligned in memory, so the distance from the start of one row to the start of the next, called the stride, can be larger than the width times the bytes per pixel; a program that ignores it reads each row starting a little off, and the image comes out sheared diagonally.
So reading a camera frame takes three facts: its width and height, its format, and its stride. With those, the frame is an ordinary array of integers that any program can index, and finding a lane, an obstacle or a ground target in it is the work of computer vision, which starts exactly where this array ends.
How much data, and which wire can carry it
A camera's data rate is plain multiplication: width times height times bytes per pixel gives the bytes in one frame, and times the frame rate gives the bytes per second. A modest 640 by 480 color frame at three bytes per pixel is 921,600 bytes, and thirty of them a second is about 27.6 megabytes a second, 221 megabits per second. A 1920 by 1080 color stream at the same rate is about 1.5 gigabits per second, and even sent raw, at 10 bits per photosite before any color is filled in, it is 622 megabits per second. For comparison, a motion sensor read a thousand times a second, a dozen bytes at a time, produces about 0.1 megabits per second. A camera's numbers are a thousand times larger or more, and they are what decide the interface.
SPI is the fast bus a microcontroller board offers, and at an example clock of 20 MHz it moves 20 megabits per second. One 640 by 480 color frame takes 0.37 seconds to cross it, fewer than three frames a second. That does not rule SPI out; it changes what a camera on it can do. A camera on SPI has to send small frames (a 160 by 120 grayscale frame crosses the same link in under 8 milliseconds), or few of them, or compress each frame before sending it, and the controller gets an occasional glance at the scene rather than a stream.
USB is the next step. The USB 2.0 specification signals at 480 megabits per second, but a stream that reserves guaranteed time on the bus, the kind a video stream can use, gets at most 192 megabits per second per endpoint. A 640 by 480 stream at 30 frames a second in the two-byte YUYV format needs about 147 and fits; 1920 by 1080 in the same format needs about 995, more than even the full signaling rate. So a USB 2.0 camera that offers full HD at 30 frames a second sends it compressed, and the USB Video Class, the USB standard for video devices, defines compressed payloads such as MJPEG and H.264 alongside uncompressed ones.
The camera connector on a single-board computer is wired for MIPI's Camera Serial Interface 2 (CSI-2), a link built for nothing but moving pixels from a sensor to a processor. It runs over one or more data lanes, and on the D-PHY physical layer each lane carries two bits per cycle of its link clock. As an example, a two-lane link clocked at about 450 MHz carries about 900 megabits per second on each lane and about 1.8 gigabits per second together, nearly three times what that raw full-HD stream needs, and version 3.0 of D-PHY allows up to 9 gigabits per second on each lane. The cost is that the processor needs a CSI-2 receiver and the memory to hold whole frames, which is exactly what a single-board computer's camera connector is there to provide.
Every frame arrives late
A camera frame describes the world as it was, never as it is. Between light reaching the sensor and a program acting on it there are several waits, and they add up. The light itself is gathered over the whole exposure. On a rolling sensor the rows are then read out over tens of milliseconds. The frame crosses the link, may be decoded or converted, and lands in a buffer. Only then does the program start its own work, which can take longer than everything before it.
The buffer is a wait that is easy to forget. The Linux kernel's camera interface keeps captured frames in first-in, first-out queues, so frames are handed to the program in the order they were taken. A program that is slower than the camera does not get the newest frame when it asks; it gets the oldest one still waiting. Code that has to act on the present either keeps up with the frame rate or deliberately throws stale frames away and takes the latest.
Here is one example tally for a robot car with a camera at 30 frames a second: up to 33 milliseconds of exposure, about 30 of rolling readout, one frame of 33 milliseconds waiting in the queue, and a program that takes 50 milliseconds to find the lane. That is about 150 milliseconds from light to steering command, and a car moving at 2 meters per second covers about 30 centimeters in that time. The numbers change with every setup; the shape of the sum does not.
Frame rate and latency are different properties, and mixing them up is a classic mistake. Frame rate is how often the robot looks; latency is how old each look is by the time it counts. A camera running at 60 frames a second still delivers stale frames to a program that takes 100 milliseconds to read one, and a controller that treats every frame as the present will steer for where the car used to be.
A camera on a car and a camera on a drone
On a small self-driving car, the natural home for the camera is a module on the single-board computer's camera connector, streaming frames over CSI-2 into memory, where a program reads each one as an array of numbers. Every property of the sensor turns into a driving limit. Resolution sets the smallest thing the car can make out, and every extra pixel is more work for the program before it can steer. Frame rate sets how far the car travels blind between looks: at 30 frames a second and 2 meters per second, about 7 centimeters. Latency sets how stale each look is, and in a dim room the noise in short exposures sets how sure the program can be of an edge. What the software then does with the array, finding lanes and obstacles, belongs to computer vision.
On a survey drone the same mechanism is scaled up and slowed down. The example job's camera has 5472 by 3648 photosites, about 20 million, and it takes one still photo roughly every three seconds and stores it on the aircraft instead of streaming it to a program. How long a photo waits before anything reads it stops mattering. The instant it was captured matters more than ever, because every pixel is now a measurement and the aircraft is moving. The size of each pixel, a lens that never changes, when each row was exposed and how exactly the moment of exposure is recorded are what decide whether the ground can be measured from the photos, and survey payloads takes those up as instrument requirements; a rolling readout of 30 to 40 milliseconds on a moving aircraft is one reason the example job's camera has a mechanical shutter instead.
The two robots ask different questions of one sensor. The car asks how fast and how fresh; the drone asks how many and how exact. Both answers start in the same place: photosites counting light, a converter turning counts into numbers, rows read in turn, and a stream of arrays that has to fit down a wire. A builder who can say what each of those numbers is for a given camera can tell, before buying it, whether it will do the job.
Sources
The published studies, standards and guidance this page cites. Links open on other sites.
- EMVA Standard 1288, Release 4.0 Linear: Standard for Characterization of Image Sensors and Cameras (European Machine Vision Association, 2021) www.emva.org
- Raw Bayer Formats, Linux Media Infrastructure userspace API (Linux kernel documentation) docs.kernel.org
- Color imaging array, US Patent 3,971,065 (Bryce E. Bayer, 1976) patents.google.com
- Demosaicking: Color filter array interpolation (IEEE Signal Processing Magazine, 2005) doi.org
- Photogrammetric accuracy and modeling of rolling shutter cameras (ISPRS Annals, 2016) isprs-annals.copernicus.org
- Standard Image Formats, Linux Media Infrastructure userspace API (Linux kernel documentation) docs.kernel.org
- Universal Serial Bus Specification, Revision 2.0 (USB Implementers Forum) www.usb.org
- USB Device Class Definition for Video Devices, Revision 1.5 document set (USB Implementers Forum) www.usb.org
- Camera Serial Interface 2 (MIPI CSI-2) (MIPI Alliance) www.mipi.org
- Pixel data transmitter and receiver drivers (Linux kernel documentation) docs.kernel.org
- MIPI D-PHY (MIPI Alliance) www.mipi.org
- Streaming I/O (Memory Mapping), Linux Media Infrastructure userspace API (Linux kernel documentation) docs.kernel.org
Next on your path to Fly a site and deliver a survey-grade map: GPS / GNSS ▸