Cameras and calibration
UAT 205 Sensors and Instrumentation Systems
Lesson
By the end of this module you will be able to
- Explain the pinhole camera model and intrinsics such as focal length in pixels and principal point
- Compute the effect of radial lens distortion on pixel position and ground distance
- Explain checkerboard camera calibration with Zhang's method
- Assess calibration with reprojection error and state the definition used
Why this matters
The camera is the richest sensor on a drone, used for mapping, counting plants and visual navigation. But an image projects a 3D world onto a 2D plane through an imperfect lens. Without knowing the camera’s parameters and lens distortion, distances measured from images are wrong, maps curve and visual navigation drifts. The drone knowledge base’s camera and IMU calibration unit stresses that calibration is not a single number: it belongs to that specific camera, lens and resolution.
The pinhole camera model
The pinhole model assumes every ray passes through a single point, the centre of projection. A world point at lands on the image plane at (normalised coordinates), then converts to pixels using the focal length in pixels , where is the pixel size, and the principal point . These values are the intrinsics, written as the matrix (Hartley and Zisserman, 2004; Szeliski, 2022).
Lens distortion
Real lenses bend light unevenly across the image. The model of Brown (1966), used by OpenCV, has radial distortion and tangential distortion . Wide-angle drone lenses often have negative , called barrel distortion: the farther from the centre, the more the image is pulled inward, so straight lines near the edges curve.
Example 1 How far distortion moves points on the ground
A camera with 8.8 mm focal length, 3.3 µm pixels and a 4,000-pixel-wide image looks straight down from 100 m. The lens has , (hypothetical values).
FX = 8.8e-3 / 3.3e-6 # focal length in pixels
CX = 2000.0
K1, K2 = -0.12, 0.03
Z = 100.0 # m altitude
GSD = Z / FX # m per pixel at the image centre
print(f"fx {FX:.1f} px, GSD {GSD * 100:.2f} cm/px")
for X in (0, 10, 30, 50, 70):
x = X / Z
r2 = x * x
xd = x * (1 + K1 * r2 + K2 * r2 * r2)
u_ideal, u_real = FX * x + CX, FX * xd + CX
shift = u_ideal - u_real
print(f"X {X:>2} m: ideal u {u_ideal:7.1f}, distorted u {u_real:7.1f}, "
f"shift {shift:5.1f} px = {shift * GSD:.2f} m on the ground")
fx 2666.7 px, GSD 3.75 cm/px
X 0 m: ideal u 2000.0, distorted u 2000.0, shift 0.0 px = 0.00 m on the ground
X 10 m: ideal u 2266.7, distorted u 2266.3, shift 0.3 px = 0.01 m on the ground
X 30 m: ideal u 2800.0, distorted u 2791.6, shift 8.4 px = 0.32 m on the ground
X 50 m: ideal u 3333.3, distorted u 3295.8, shift 37.5 px = 1.41 m on the ground
X 70 m: ideal u 3866.7, distorted u 3770.4, shift 96.3 px = 3.61 m on the ground
At the centre of the image distortion has almost no effect, but near the edge points shift by nearly a hundred pixels, several metres on the ground. Without calibration, a map stitched from images warps into a bowl or dome.
Calibration with Zhang’s method
Zhang (2000) proposed a method using a planar pattern, such as a checkerboard, photographed in many poses. The software finds the square corners in every image, then solves for , the distortion coefficients and the board pose in each image so that the reprojected corners best match the detected ones. OpenCV’s calibration tutorial uses this method. Key points:
- Enter the number of inner corners and the square size in the correct units.
- Photograph the board all over the image, especially at edges and corners, where distortion is largest.
- Lock focus and resolution to match how the camera will be used.
The quality measure is the reprojection error, the difference between detected corners and corners reprojected with the estimated parameters. The drone knowledge base’s unit F16 warns that there are two definitions, RMS per point (divided by ) and RMS per component (divided by ), which differ by a factor of √2, so a report must always state the definition.
Example 2 Per-image reprojection error
Residuals (dx, dy) in pixels for four corners in five images (hypothetical, reduced from a real set with dozens of corners per image).
import math
import statistics as st
residuals = {
"img01": [(0.2, -0.1), (-0.3, 0.2), (0.1, 0.1), (0.0, -0.2)],
"img02": [(0.1, 0.3), (-0.2, -0.1), (0.2, 0.0), (-0.1, 0.2)],
"img03": [(1.8, -1.2), (2.1, 0.9), (-1.6, 1.5), (1.9, -1.4)],
"img04": [(-0.2, 0.1), (0.3, -0.2), (0.1, 0.2), (-0.1, -0.1)],
"img05": [(0.2, 0.2), (-0.1, 0.1), (0.0, -0.3), (0.2, -0.1)],
}
def rmse(pts, per_axis=False):
total = sum(dx * dx + dy * dy for dx, dy in pts)
return math.sqrt(total / (len(pts) * (2 if per_axis else 1)))
every = [p for pts in residuals.values() for p in pts]
print(f"all images: {rmse(every):.3f} px per point, {rmse(every, True):.3f} px per axis")
per_image = {k: rmse(v) for k, v in residuals.items()}
limit = 2 * st.median(per_image.values())
for k, v in per_image.items():
print(f"{k}: {v:.3f} px {'<- check this image' if v > limit else ''}")
kept = [p for k, pts in residuals.items() if per_image[k] <= limit for p in pts]
print(f"without flagged images: {rmse(kept):.3f} px per point")
all images: 1.031 px per point, 0.729 px per axis
img01: 0.245 px
img02: 0.245 px
img03: 2.252 px <- check this image
img04: 0.250 px
img05: 0.245 px
without flagged images: 0.246 px per point
A single abnormal image, for example a blurred one or one with misdetected corners, pulls the overall figure up several-fold. Look at that image before deciding to drop it, and check the result with a separate image set not used for calibration. A low reprojection error alone does not prove the calibration is right.
Module lab
Lab: camera calibration with OpenCV
- Print a checkerboard, measure the real square size with calipers and mount it on a flat, rigid board.
- Take at least 20 images in many poses, covering the whole image including the edges, with focus locked.
- Follow OpenCV’s calibration tutorial (or lab L11 in the drone knowledge base), recording , the distortion coefficients and the reprojection error with its definition.
- Use the code from Example 2 to find abnormal images, inspect the cause and recalibrate.
- Undistort one aerial image and compare straight lines near the edges before and after.
Common mistakes
Watch out
- Entering the square size in the wrong unit.
- Photographing the board only in the centre of the image.
- Changing resolution or zoom after calibration.
- Reporting reprojection error without its definition.
- Dropping high-error images without looking at the cause.
Summary
- The pinhole model projects points with and , the camera’s intrinsics.
- Real lenses have radial and tangential distortion, strongest at the image edges.
- Zhang’s method uses many images of a planar board to find intrinsics and distortion.
- Reprojection error must state its definition, be checked per image and be verified with an independent image set.
Check your understanding
- A 4.5 mm focal length with 1.5 µm pixels gives what ?
- A point at m, m with and lands at what pixel (ignoring distortion)?
- What sign does have for barrel distortion?
- An RMS of 0.5 px per point equals what RMS per component?
- Why must the checkerboard also appear near the image edges?
Answers
- px
- Negative.
- px
- Distortion is largest at the edges; without data there, the estimate is inaccurate in that region.
Key formulas
| Pinhole projection | |
| Radial distortion | |
| Reprojection RMSE per point |
Key references
- Zhang, Z. (2000). A flexible new technique for camera calibration. IEEE Transactions on Pattern Analysis and Machine Intelligence, 22(11), 1330–1334. link
- Brown, D. C. (1966). Decentering distortion of lenses. Photogrammetric Engineering, 32(3), 444–462.
- OpenCV. Camera calibration (Python tutorial). OpenCV 4.x documentation. link
- Hartley, R., & Zisserman, A. (2004). Multiple view geometry in computer vision (2nd ed.). Cambridge University Press. link
- Szeliski, R. (2022). Computer vision: Algorithms and applications (2nd ed.). Springer. link
Further reading
Study the assigned knowledge units in advance, review media and take the module quiz
In class / field
Lab or field practice from worksheets with a safety checklist
Learning evidence: Checked worksheets and quiz results