Foundations
Camera Intrinsic and Extrinsic Parameters
The parameters of the pinhole camera matrix P = K[R | t], split into intrinsics K, which map camera coordinates to pixels, and extrinsics R and t, which place the camera in the world.
intermediate
A camera’s parameters say how a point in the world becomes a pixel. They split into two groups: extrinsic parameters, which say where the camera is and which way it points, and intrinsic parameters, which describe the camera itself, turning a direction in front of the camera into a pixel position. Together they form the camera matrix , which extends the pinhole camera model from a camera fixed at the origin with metric image coordinates to a real camera anywhere in the scene producing pixel coordinates.
Definition
The extrinsic parameters are a rotation and a translation that transform a point from world coordinates to camera coordinates. The intrinsic parameters are the focal lengths in pixels and , the principal point , and the skew , collected in the upper-triangular intrinsic matrix (or calibration matrix) . Lens distortion coefficients are usually counted as further intrinsic parameters. Intrinsics stay fixed as the camera moves, as long as the focus and zoom do not change; extrinsics change with every movement.
Intuition
Imaging a point happens in three steps. First, express the point relative to the camera: where it lies to the camera’s right, below it, and in front of it. That is a rigid motion, the extrinsics. Second, project it through the pinhole: divide by depth to get its direction, a 2D point on a plane one unit in front of the camera. Third, convert that direction into a pixel: scale by the focal length in pixels and shift so that the origin is at the image corner instead of the optical axis. That is the job of the intrinsics. Moving the camera changes only the first step; swapping the lens or resizing the image changes only the third.
Formal Definition
The camera matrix
With a world point and its pixel in homogeneous coordinates,
where is the depth of the point in the camera frame. This is the form used by Hartley and Zisserman (2004) and, without skew, by OpenCV’s calib3d module.
Extrinsics
The extrinsics map world coordinates to camera coordinates:
is a rotation matrix (, ) and is the position of the world origin expressed in camera coordinates. It is not the camera’s position. The camera center is the world point that maps to , so
The rows of are the camera’s axes written in world coordinates; the third row is the direction of the optical axis. The homogeneous camera center is the null vector of : , so the center is the one point whose image is undefined.
Intrinsics
In camera coordinates the projection to pixels is
- Focal lengths in pixels. A lens of focal length (in millimeters) on a sensor with pixel pitch (in millimeters per pixel) gives and . Hartley and Zisserman write the same thing as , with pixels per unit length. The ratio is the aspect ratio, 1 for square pixels.
- Principal point. is the pixel where the optical axis meets the image. It is usually near the image center but rarely exactly at it.
- Skew. is nonzero only if the pixel grid’s axes are not perpendicular. For modern sensors , and many libraries, OpenCV included, omit it.
Normalized image coordinates
Applying to a pixel removes the intrinsics:
These normalized coordinates are what an ideal camera with and the principal point at the origin would measure, and is the direction of the ray through the pixel in the camera frame. Methods that care only about rays, such as relative pose estimation with the essential matrix and triangulation, work in normalized coordinates once is known.
Distortion
Real lenses add lens distortion, which OpenCV models as a nonlinear function applied to the normalized coordinates before : radial coefficients , tangential coefficients , thin-prism coefficients , and two sensor-tilt angles. Because these depend on the lens and not on the pose, they are intrinsic parameters, but they are not part of , and alone no longer describes the camera once they are nonzero.
Properties
Degrees of freedom
has 5 parameters (), has 3 (a rotation), and has 3, for 11 in total. This matches : it has 12 entries but is defined only up to scale, leaving 11 (Hartley and Zisserman, 2004). Conversely, any matrix whose left block is invertible can be written, up to scale, as , as the decomposition below shows.
Field of view
For an image pixels wide and high, with the principal point at the center,
The field of view depends only on the ratio of image size to focal length, so it is unchanged by resizing.
Resizing and cropping
belongs to a specific image resolution. Scaling an image by a factor multiplies , , , and by , as the OpenCV documentation notes; non-uniform scaling multiplies the and entries by their own factors. This is exact if pixel centers lie at half-integer coordinates, so that the image spans . If instead pixel centers lie at integers, as in OpenCV, the image spans , and a resize that maps the image’s outer edges onto each other sends to ; the principal point then becomes , a sub-pixel difference that matters for precise work (see digital image for the two conventions). Cropping a window whose top-left corner is at leaves the focal lengths unchanged and shifts the principal point to . Using a calibrated at one resolution on images of another is a common silent error.
Decomposing P
Given a camera matrix, for example one estimated from point correspondences, , , and can be recovered. Write with . An RQ decomposition factors into an upper-triangular matrix times an orthogonal matrix, which is exactly the form (Hartley and Zisserman, 2004). The factorization is unique only up to the signs of the columns of and rows of , so the signs are fixed by requiring a positive diagonal in and , flipping the overall sign of if necessary, since and represent the same camera. Then , and dividing by its bottom-right entry restores the usual normalization. OpenCV provides decomposeProjectionMatrix, built on its RQDecomp3x3.
Conventions
The world-to-camera transform used above is the convention of Hartley and Zisserman and of OpenCV, whose documentation describes and as the change of coordinates from world to camera. Many robotics and graphics tools instead store the camera pose, the camera-to-world transform
whose translation is the camera’s position. Both are rigid transforms and each is the inverse of the other. Confusing them produces cameras that sit in the wrong place and point the wrong way, often without any error message. Axis orientation is a separate convention: OpenCV’s camera frame has down and forward, while OpenGL’s camera looks along with up (see pinhole camera model). When combining data from different sources, check which transform direction and which axes each one uses.
Examples
The NumPy code below builds from a lens and sensor, sets up world-to-camera extrinsics, projects points, recovers the camera center, computes the field of view, shows how changes when the image is halved and cropped, and decomposes back into , , and .
import numpy as np
from scipy.linalg import rq
from scipy.spatial.transform import Rotation
np.set_printoptions(precision=3, suppress=True)
# Intrinsics: 4 mm lens, 2 um pixels, 1280 x 960 image
f_mm, pitch_mm = 4.0, 0.002
fx = fy = f_mm / pitch_mm # 2000 px
K = np.array([[fx, 0.0, 640.0],
[0.0, fy, 480.0],
[0.0, 0.0, 1.0]])
# Extrinsics, world-to-camera: X_cam = R X_world + t
R = Rotation.from_euler("xyz", [5, -5, 2], degrees=True).as_matrix()
C_true = np.array([1.0, -0.5, -6.0]) # camera centre in the world
t = -R @ C_true
P = K @ np.hstack([R, t[:, None]]) # 3x4 camera matrix
def project(P, X):
x = np.hstack([X, np.ones((len(X), 1))]) @ P.T
return x[:, :2] / x[:, 2:]
X = np.array([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 1.0]])
print("pixels:\n", project(P, X))
print("depths Z_cam:", (X @ R.T + t)[:, 2])
# Camera centre: C = -R^T t, which is also the null vector of P
_, _, Vt = np.linalg.svd(P)
print("C = -R^T t:", -R.T @ t, " null(P):", Vt[-1, :3] / Vt[-1, 3])
# Field of view from f and the image width
print("horizontal FOV: %.2f deg" % np.degrees(2 * np.arctan(1280 / (2 * fx))))
# Halve the resolution, then crop a window starting at pixel (100, 50)
S = np.diag([0.5, 0.5, 1.0])
K_half = S @ K
K_crop = np.array([[1, 0, -100], [0, 1, -50], [0, 0, 1]]) @ K_half
print("K at 640 x 480:\n", K_half)
print("K after crop:\n", K_crop)
print("halved pixels match:", np.allclose(project(S @ P, X), 0.5 * project(P, X)))
def decompose(P):
"""Split P = K [R | t] using an RQ decomposition of its left 3x3 block."""
K, R = rq(P[:, :3])
D = np.diag(np.sign(np.diag(K))) # force a positive diagonal on K
K, R = K @ D, D @ R # D @ D = I, so K @ R is unchanged
if np.linalg.det(R) < 0: # P is known only up to sign
K, R = -K, -R
t = np.linalg.solve(K, P[:, 3])
return K / K[2, 2], R, t
for c in (1.0, -3.0): # any nonzero scale of P
K_est, R_est, t_est = decompose(c * P)
print(f"scale {c}: K =\n", np.round(K_est, 6) + 0.0)
print(" R ok:", np.allclose(R_est, R), " t ok:", np.allclose(t_est, t))
Output:
pixels:
[[125.966 453.64 ]
[465.418 465.616]
[169.255 716.709]]
depths Z_cam: [5.911 5.998 6.99 ]
C = -R^T t: [ 1. -0.5 -6. ] null(P): [ 1. -0.5 -6. ]
horizontal FOV: 35.49 deg
K at 640 x 480:
[[1000. 0. 320.]
[ 0. 1000. 240.]
[ 0. 0. 1.]]
K after crop:
[[1000. 0. 220.]
[ 0. 1000. 190.]
[ 0. 0. 1.]]
halved pixels match: True
scale 1.0: K =
[[2000. 0. 640.]
[ 0. 2000. 480.]
[ 0. 0. 1.]]
R ok: True t ok: True
scale -3.0: K =
[[2000. 0. 640.]
[ 0. 2000. 480.]
[ 0. 0. 1.]]
R ok: True t ok: True
The translation is not the camera position; is, and it agrees with the null vector of . The decomposition recovers , , and even from : the sign fix makes and come out the same, and dividing by ’s bottom-right entry and solving with the unnormalized cancel the scale.
Common Misconceptions
- “ is where the camera is.” In the world-to-camera convention, is the world origin in camera coordinates. The camera center is .
- “The focal length on the lens is .” is in pixels and depends on the pixel pitch and on any resizing of the image. A 4 mm lens on 2 µm pixels gives 2000 pixels, which becomes 1000 if the image is downsampled by two.
- “The principal point is the image center.” It is close to the center but usually offset by some pixels, and assuming the center is a frequent source of systematic error in metric work.
- “ is a property of the camera alone.” It is a property of the camera at a given focus, zoom, and image resolution. Refocusing, zooming, digital cropping, or resizing all change it.
- “Every pose matrix means the same thing.” A matrix may be world-to-camera or camera-to-world, and its camera axes may follow the vision or the graphics convention. The matrix itself does not say which.
Where It Is Used
Intrinsics and extrinsics are estimated by camera calibration, which observes a known target, usually a planar pattern, in several views and fits all parameters, including lens distortion, by minimizing reprojection error. Once is known, two-view geometry can be reduced to the essential matrix in normalized coordinates, and points seen in several calibrated views can be triangulated. Perspective-n-Point estimates the extrinsics of a calibrated camera from known 3D points, which is how augmented reality anchors virtual content and how visual localization works. Structure from motion and SLAM estimate the extrinsics of every frame, and sometimes the intrinsics too, by bundle adjustment; filtering approaches such as the extended Kalman filter track camera pose over time. Multi-camera rigs on vehicles and robots store each camera’s intrinsics together with its extrinsics relative to the rig, and rendering pipelines use the same parameters to place a virtual camera.
Related
- Lens Distortion
The systematic deviation of a real lens from the pinhole model's straight-line projection, which bends straight lines in the image and is modeled, estimated, and removed as part of camera calibration.
- Homogeneous Coordinates
Representing a point by a vector with one extra coordinate, defined only up to scale, so that translations, perspective projections, and points at infinity can all be handled with matrix multiplication.
- Projective Geometry
The geometry of properties that survive perspective projection, such as straightness, incidence, and the cross-ratio, which underlies how computer vision models cameras and relates images.
- Digital Image
A digital image is a grid of samples of a continuous scene, each quantized to a finite set of values and stored as an array of numbers.