AI Wiki中文/EN

Image formation and camera models

图像形成与相机模型

Project a 3D point, recover its viewing ray, and check which way a camera translation moves its pixel.

On this pageIntuitionMathematics & methodImplementationLimitationsExercisesResearch connections

A 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 PwP_w and its camera coordinates as PcP_c. A rigid world-to-camera transform uses a proper rotation RR and translation tt:

Pc=RPw+t,RTR=I,det⁡R=1.P_c=RP_w+t,\qquad R^TR=I,\qquad \det R=1.

The camera centre CC is the world point whose camera coordinates are zero. Solving RC+t=0RC+t=0 gives:

C=−RTt.C=-R^Tt.

Thus tt is not generally the camera’s position in the world. With unchanged axes and a camera centre at (1,0,0)(1,0,0), the world-to-camera translation is (−1,0,0)(-1,0,0).

For a point (Xc,Yc,Zc)(X_c,Y_c,Z_c) in front of the camera, similar triangles give normalized coordinates Xc/ZcX_c/Z_c and Yc/ZcY_c/Z_c. Multiplying by focal lengths measured in pixels, then adding the principal point, gives:

u=fxXcZc+cx,v=fyYcZc+cy,Zc>0.u=f_x\frac{X_c}{Z_c}+c_x,\qquad v=f_y\frac{Y_c}{Z_c}+c_y,\qquad Z_c>0.

With zero skew, the same calculation in homogeneous coordinates is:

K=[fx0cx0fycy001],Zc[uv1]=K[R∣t][Pw1].K=\begin{bmatrix}f_x&0&c_x\\0&f_y&c_y\\0&0&1\end{bmatrix},\qquad Z_c\begin{bmatrix}u\\v\\1\end{bmatrix}=K[R\mid t]\begin{bmatrix}P_w\\1\end{bmatrix}.

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 (fx,fy,cx,cy)=(100,120,32,24)(f_x,f_y,c_x,c_y)=(100,120,32,24) and (Xc,Yc,Zc)=(1,0.5,5)(X_c,Y_c,Z_c)=(1,0.5,5), the result is (52,36)(52,36). Doubling all three camera coordinates leaves both ratios unchanged. A pixel therefore identifies a ray, not a unique 3D point. Given camera-Z depth zz, backprojection is:

Pc=z[(u−cx)/fx(v−cy)/fy1].P_c=z\begin{bmatrix}(u-c_x)/f_x\\(v-c_y)/f_y\\1\end{bmatrix}.

This zz is distance along the optical axis, not Euclidean distance from the camera. Here the latter is 26.25\sqrt{26.25}, whereas camera-Z depth is five. World coordinates are recovered by Pw=RT(Pc−t)P_w=R^T(P_c-t) 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?

Choose one answer

Learning objectives

  • Derive pixel projection and distinguish coordinate frames.
  • Explain why one pixel does not determine depth.

Prerequisites & connections

Explore related knowledge →

References

  1. Camera Calibration and 3D Reconstruction — OpenCV 4.10.0
    OpenCV contributors
  2. 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:

Related topics

No matches. Try a synonym or acronym.

0 results shown

Wrap the whole query in double quotes for a phrase match.