Image formation and camera models
图像形成与相机模型
Project a 3D point, recover its viewing ray, and check which way a camera translation moves its pixel.
image-formationA question to test
Move a camera one metre to the right. Does a stationary object’s horizontal pixel coordinate increase or decrease? The answer depends on which coordinate system the translation belongs to. This small sign mistake can make a robot aim away from its target even when every matrix has the expected shape.
A photograph assigns pixel coordinates and intensities to light arriving through an optical system. This chapter models the geometric location of a projected point. Exposure, reflectance, blur and sensor noise determine its appearance; they are not estimated by the pinhole equations. Keep that distinction when using a camera model to generate or interpret an image.
Our synthetic example uses a virtual image plane in front of the camera, positive camera Z pointing forward, and pixel axes aligned with camera X and Y. Two points at different distances will land on the same pixel. Predict why before running the program.
The model and its derivation
Write a world point as and its camera coordinates as . A rigid world-to-camera transform uses a proper rotation and translation :
The camera centre is the world point whose camera coordinates are zero. Solving gives:
Thus is not generally the camera’s position in the world. With unchanged axes and a camera centre at , the world-to-camera translation is .
For a point in front of the camera, similar triangles give normalized coordinates and . Multiplying by focal lengths measured in pixels, then adding the principal point, gives:
With zero skew, the same calculation in homogeneous coordinates is:
The intrinsics convert camera directions to pixel coordinates; extrinsics change coordinate frames. OpenCV’s introduction uses this distinction. Zhang’s report includes a more general intrinsic matrix with skew; our example deliberately sets that entry to zero. Camera Calibration and 3D Reconstruction — OpenCV 4.10.0 A Flexible New Technique for Camera Calibration — MSR-TR-98-71
For and , the result is . Doubling all three camera coordinates leaves both ratios unchanged. A pixel therefore identifies a ray, not a unique 3D point. Given camera-Z depth , backprojection is:
This is distance along the optical axis, not Euclidean distance from the camera. Here the latter is , whereas camera-Z depth is five. World coordinates are recovered by once the pose and depth are known.
Run a small experiment
Save this as example.py and run it with Python 3.12 and NumPy 1.26.4. Arrays store points as rows, so the code uses points @ R.T; it implements the column-vector equation above without changing its meaning. The example has no image file, fitted parameters or hidden model weights.
import numpy as np
def intrinsics(values):
k = np.asarray(values, dtype=float)
if k.shape != (4,) or not np.isfinite(k).all() or min(k[:2]) <= 0:
raise ValueError("need finite fx, fy > 0 and cx, cy")
return k
def pose(rotation, translation):
r, t = np.asarray(rotation, dtype=float), np.asarray(translation, dtype=float)
if r.shape != (3,3) or t.shape != (3,) or not np.isfinite(r).all() or not np.isfinite(t).all():
raise ValueError("need finite 3x3 rotation and length-3 translation")
if not np.allclose(r.T @ r, np.eye(3), atol=1e-10, rtol=0) or not np.isclose(np.linalg.det(r), 1, atol=1e-10, rtol=0):
raise ValueError("rotation must be orthonormal with determinant +1")
return r, t
def project(points, calibration, rotation=np.eye(3), translation=np.zeros(3)):
p = np.asarray(points, dtype=float)
if p.ndim != 2 or p.shape[1] != 3 or not np.isfinite(p).all():
raise ValueError("points must be a finite Nx3 array")
fx, fy, cx, cy = intrinsics(calibration)
r, t = pose(rotation, translation)
camera = p @ r.T + t
if np.any(camera[:,2] <= 0):
raise ValueError("all points must lie strictly in front of the camera")
with np.errstate(over='raise', divide='raise', invalid='raise'):
result = camera[:,:2] / camera[:,2,None] * [fx,fy] + [cx,cy]
if not np.isfinite(result).all():
raise ValueError("projection is outside finite arithmetic")
return result
def backproject(pixels, depths, calibration):
uv, z = np.asarray(pixels, dtype=float), np.asarray(depths, dtype=float)
if uv.ndim != 2 or uv.shape[1] != 2 or z.shape != (len(uv),):
raise ValueError("need Nx2 pixels and one camera-Z depth per pixel")
if not np.isfinite(uv).all() or not np.isfinite(z).all() or np.any(z <= 0):
raise ValueError("pixels and positive depths must be finite")
fx, fy, cx, cy = intrinsics(calibration)
return np.column_stack(((uv-[cx,cy])/[fx,fy]*z[:,None], z))
if __name__ == '__main__':
k = [100,120,32,24]
points = [[1,.5,5],[2,1,10]]
print('pixels:', project(points,k).tolist())
print('camera point:', backproject([[52,36]],[5],k).tolist())
print('camera shifted right:', project(points[:1],k,translation=[-1,0,0]).tolist())
print('world camera center:', (-np.eye(3).T @ np.array([-1.,0,0])).tolist())
Expected output from the checked environment:
pixels: [[52.0, 36.0], [52.0, 36.0]]
camera point: [[1.0, 0.5, 5.0]]
camera shifted right: [[32.0, 36.0]]
world camera center: [1.0, 0.0, 0.0]
The first two points share a viewing ray. Moving the camera right reduces the first point’s camera X from one to zero, so it moves to the principal horizontal coordinate, 32. Backprojection recovers camera coordinates only because depth was supplied.
For N points, projection takes O(N) arithmetic and O(N) output storage with fixed-size matrices. The checks compare it with an independently assembled homogeneous projection matrix, including a nonidentity rotation; they also test resizing, invalid depths, a reflection passed as a rotation, and ray-depth ambiguity.
Where the method breaks
A mathematically projectable point need not be visible: it may fall outside the sensor or lie behind another object. This program rejects points on or behind the camera plane but does not perform image-bound checks or occlusion reasoning. Floating-point overflow is a numerical failure, not a faraway valid pixel.
Real lenses can distort straight lines. A rolling shutter can expose different rows at different poses. Motion blur and lighting affect intensities. These effects require additional models; changing the focal length cannot absorb them all. Calibration estimates model parameters from observations, whereas this program assumes them known. Zhang’s planar-pattern method is a next step, not a procedure implemented here. A Flexible New Technique for Camera Calibration — MSR-TR-98-71
Resizing an image by a pure coordinate scale also scales focal lengths and principal-point coordinates. Cropping changes the coordinate origin instead. A real resampler’s pixel-centre convention may add an offset, so derive the actual image-coordinate transform before updating K. Neither operation changes the camera’s physical pose.
Exercises with answers
1. Why do (1, 0.5, 5) and (2, 1, 10) project together?
Answer. Both have X/Z=0.2 and Y/Z=0.1. One pixel cannot distinguish their depths.
2. The camera centre moves to (1, 0, 0), with R=I. What is t?
Answer. t=(−1,0,0). The first point projects to (32,36), not (72,36).
3. Can a measured ray length of five be passed as Z depth for pixel (52,36)?
Answer. No. Its normalized ray is (0.2,0.1,1), whose length is √1.05. Camera-Z depth must be 5/√1.05.
4. Crop 10 pixels from the left and 4 from the top. What changes?
Answer. With the same pixel spacing, fx and fy stay fixed and the principal point becomes (22,20). Reprojecting the example gives (42,32).
Sources and next steps
Read OpenCV’s pinhole introduction for coordinate conventions and Zhang’s technical-report model for the connection to calibration. The report has a 1998 date and later listed corrections; this is not a claim that the whole report or its experiments were reproduced. Camera Calibration and 3D Reconstruction — OpenCV 4.10.0 A Flexible New Technique for Camera Calibration — MSR-TR-98-71
Review matrix multiplication if the transform order is unfamiliar. Continue with image filtering to see how neighbourhood operations change a recorded image while leaving this geometric model separate.
Make a prediction, then check
For R=I and camera centre C=(1,0,0), what is world-to-camera t?
Learning objectives
- Derive pixel projection and distinguish coordinate frames.
- Explain why one pixel does not determine depth.
Prerequisites & connections
Explore related knowledge →References
- Camera Calibration and 3D Reconstruction — OpenCV 4.10.0
OpenCV contributors - A Flexible New Technique for Camera Calibration — MSR-TR-98-71
Zhengyou Zhang · 1998
Version1 · Editorial status: Recorded technical checks completed
View technical check record (AI)
Codex · 2026-09-07 · Codex single-AI-author technical check: bounded primary-source passages, explicit camera, filter, descriptor and local-motion models, executed programs, independent mathematical references, input boundaries and bilingual alignment. Not independent human or second-agent review; no full-system research reproduction claimed.
- Single-agent authored technical review; runnable example, exact or literal reference checks, explicit assumptions and matching bilingual equations/exercises. Automated execution and rendering results recorded separately.
- 6 tests: pinhole ray ambiguity, camera-centre sign, independently assembled homogeneous projection with20 nontrivial-pose points, Z versus ray depth, coordinate scaling and invalid inputs.
- Single AI author compared all six sections, formulas, examples, source scopes and four exercise/answer pairs across both languages.35 tests across six chapters passed before freezing; no independent human review claimed.
- Complete bilingual prose and corresponding exercises promoted with formal status and SHA binding. Algorithm tests read formal MDX; historical essays claim no executable program or computational tests.
Source locations checked:
- Camera Calibration and 3D Reconstruction — OpenCV 4.10.0 · Pinhole introduction and world-to-camera/intrinsic equations; image coordinate scaling.
- A Flexible New Technique for Camera Calibration — MSR-TR-98-71 · Report header; §2.1 model on physical page4 and planar homography context on pages5–6.
Related topics