1. Home
  2. Explore
  3. Engineering
  4. Camera Matrix in Computer Vision

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Camera Matrix in Computer Vision

Camera Matrix in Computer Vision

This note covers the camera matrix, a fundamental concept in computer vision that describes how a 3D point in world space is mapped onto a 2D image. Starting from a simple pinhole camera model, the derivation progresses through intrinsic and extrinsic parameters to arrive at the full camera matrix.


Pinhole Camera Model

Real cameras have complex optics (lenses, large apertures) that introduce distortions such as radial distortion and tangential distortion. To simplify analysis, the pinhole camera model is used:

  • An ideal pinhole camera has an infinitesimally small aperture (a single point).

  • Each point on the image plane (sensor) receives light from only one direction → sharp, blur‑free image.

  • A larger aperture would allow light from multiple directions to reach the same sensor point → blurry image.

  • Real cameras use lenses to reduce blurriness, but lenses introduce errors (distortions). Some errors (e.g., radial distortion) can be corrected later; others (tangential distortion) are often negligible with good equipment.

The pinhole model is a useful approximation because it is simple yet reasonably accurate.


Coordinate Systems

World Coordinate System

  • Arbitrary choice; common setup: x- and y-axes form the ground plane, z-axis points up.

  • However, camera coordinate systems typically align the sensor with the x- and y-axes, and the camera looks along the positive z-axis (optical axis, principal axis).

  • Different conventions exist (e.g., in computer graphics the camera often looks along the negative z-axis), which would require sign changes in formulas.

Camera Coordinate System

  • Aperture (pinhole) is placed at the origin.

  • Image plane is behind the aperture, aligned with the x- and y-axes.

  • Optical axis (z-axis) passes through the center of the image plane.

  • The sensor has physical width W and height H (in millimeters). Later, pixels will be introduced.

Key distinction: Capital letters (e.g., X, Z, F) denote physical units (millimeters); small letters (e.g., w, u, v) denote pixel units.


Intrinsic Camera Matrix

Basic Geometric Derivation

Looking at the setup from the top (x‑z plane)—the same reasoning applies to the y‑z plane:

  • Distance from image plane to aperture = focal length F (mm).

  • Horizontal angle of view is the angle between the extreme captured light rays along the x‑axis.

  • Consider a 3D point with camera‑coordinates (X, Z) (assuming the point is expressed in camera coordinates for now).

  • Light ray from the point passes through the aperture and hits the sensor on the opposite side at a negative x‑coordinate. Let that coordinate be -U (by adding a minus sign, U becomes positive when X is positive — this makes formulas cleaner).

Using similar triangles: \frac{-U}{-F} = \frac{X}{Z} \quad \Rightarrow \quad \frac{U}{F} = \frac{X}{Z}

This is the basis for the intrinsic camera matrix.

Scaling and Pixel Units

  • Multiple cameras with different focal lengths and image plane sizes can produce the same image if the ratio F/W is kept constant.

  • Specifically, if the focal length is doubled, doubling the image plane size gives the same angle of view.

  • Introduce a scaling factor k to convert physical distances to pixels.

  • Let w be the sensor width in pixels. Then: k = \frac{w}{W} \quad (\text{pixels per millimeter})

  • The image coordinate in pixels becomes kU, and the focal length in pixels becomes kF. The similar‑triangle equation becomes: \frac{wU/W}{wF/W} = \frac{X}{Z} \quad \Rightarrow \quad \frac{kU}{kF} = \frac{X}{Z} More directly: \frac{\text{pixel coordinate}}{ \text{focal length in pixels}} = \frac{X}{Z}

Principal Point Offset

  • Real sensors may not be perfectly centered on the optical axis; there is an offset u_0 (in pixels) along the x‑direction.

  • This offset shifts the image coordinates in the opposite direction: -U becomes more negative by u_0, so we add u_0 back to obtain the correct pixel coordinate.

  • The equation becomes: \frac{U}{F} = \frac{X}{Z} \quad \text{transforms to:} \quad u = \frac{f_x X}{Z} + u_0 where f_x = kF is the focal length in pixels (x‑direction).

Similarly, for the y‑direction, with offset v_0 and focal length in pixels f_y: v = \frac{f_y Y}{Z} + v_0

Matrix Form (Cartesian)

The two equations can be written in matrix form (still in Cartesian coordinates): \begin{bmatrix} u v \end{bmatrix} = \begin{bmatrix} f_x & 0 & u_0 0 & f_y & v_0 \end{bmatrix} \begin{bmatrix} X/Z Y/Z 1 \end{bmatrix}

This 2×3 matrix is part of the intrinsic matrix. Two differences from the standard 3×3 intrinsic matrix:

  1. Shear parameter s is sometimes included (for non‑square pixels or skewed sensor), but in an ideal pinhole camera it is not needed.

  2. Only two rows are shown because Cartesian coordinates are used. The third row appears when we switch to homogeneous coordinates.


Homogeneous Coordinates

Motivation

  • Cartesian coordinates cannot represent points at infinity.

  • Rotations and translations are separate operations in Cartesian; homogeneous coordinates combine them into a single matrix multiplication.

Definition

  • For a 2D Cartesian point [x, y], the corresponding homogeneous coordinates are (xS, yS, S), where S is any non‑zero scalar.

  • Homogeneous coordinates are not unique: multiplying by a non‑zero scalar yields the same Cartesian point.

  • To recover Cartesian coordinates, divide the first two entries by the third.

  • The point (x, y, 0) represents the point at infinity in the direction of the line from the origin through (x, y).

Combining Rotation and Translation

  • A rotation matrix R and translation vector t in 2D can be combined into a single 3×3 homogeneous transformation matrix: \begin{bmatrix} R & t 0 & 1 \end{bmatrix}

  • This matrix performs both rotation and translation in one operation, and its inverse is easy to compute.

Application to 3D

  • A 3D Cartesian point [X, Y, Z] becomes homogeneous (X, Y, Z, 1).

  • The tilde notation (\sim) is used to indicate equivalence up to scale: \tilde{\mathbf{x}} \sim \mathbf{P} \tilde{\mathbf{X}}


Converting the Intrinsic Matrix to Homogeneous Form

Start from the Cartesian equation: \begin{bmatrix} u v \end{bmatrix} = \begin{bmatrix} f_x & 0 & u_0 0 & f_y & v_0 \end{bmatrix} \begin{bmatrix} X/Z Y/Z 1 \end{bmatrix}

Rewrite in homogeneous coordinates:

  • On the right, represent [X, Y, Z] as (X, Y, Z, 1) and scale the intrinsic matrix to 3×4 to include a division by Z.

  • After manipulation, we get: \begin{bmatrix} u v 1 \end{bmatrix} \sim \begin{bmatrix} f_x & 0 & u_0 & 0 0 & f_y & v_0 & 0 0 & 0 & 1 & 0 \end{bmatrix} \begin{bmatrix} X Y Z 1 \end{bmatrix}

  • The left side is a homogeneous vector (pixel coordinates) and the right side is the projection of the 3D point up to scale s (where s = Z in this case).

  • This 3×4 matrix (or often the 3×3 part omitting the last column of zeros when Z is not used) is the intrinsic camera matrix K: K = \begin{bmatrix} f_x & 0 & u_0 0 & f_y & v_0 0 & 0 & 1 \end{bmatrix}


Extrinsic Camera Matrix

World‑to‑Camera Transformation

  • So far, points were given in camera coordinates. Normally, 3D points are in world coordinates.

  • The transformation from world to camera coordinates involves a rotation and translation: the extrinsic camera matrix (world‑to‑camera matrix).

Intuition from 2D Example

  • Rotating the coordinate system counter‑clockwise by some angle has the same effect as rotating the point clockwise by the same amount.

  • In general: transforming the coordinate system (e.g., rotating and translating the camera) is the inverse of transforming the object coordinates.

  • If we know the camera’s world position and orientation (camera‑to‑world transformation), the world‑to‑camera matrix is its inverse.

Constructing the Extrinsic Matrix

  • Let the camera be located at position t (world coordinates) and oriented with rotation R relative to the world axes.

  • The camera‑to‑world matrix M_{cam2world} is: M_{cam2world} = \begin{bmatrix} R & t 0 & 1 \end{bmatrix}

  • The world‑to‑camera matrix is the inverse: M_{world2cam} = M_{cam2world}^{-1} = \begin{bmatrix} R^T & -R^T t 0 & 1 \end{bmatrix}

  • Apply this 4×4 homogeneous matrix to a world point (X_w, Y_w, Z_w, 1) to obtain its camera coordinates (X_c, Y_c, Z_c, 1).


Complete Camera Matrix

The camera matrix P combines intrinsic and extrinsic parameters:

P = K \begin{bmatrix} R & t \end{bmatrix} (where K is 3×3 and [R \mid t] is 3×4, resulting in a 3×4 matrix).

Equivalently, using homogeneous coordinates: \tilde{\mathbf{x}} \sim P \tilde{\mathbf{X}}

  • \tilde{\mathbf{x}}: homogeneous image point (pixels).

  • \tilde{\mathbf{X}}: homogeneous world point.

  • P = K [R \mid t]: 3×4 camera matrix.

  • The tilde indicates equality up to a non‑zero scale factor.


Summary of Parameters

Intrinsic parameters (inside the camera):

  • Focal length in pixels f_x, f_y (may differ if pixels are non‑square).

  • Principal point (u_0, v_0) (center offset in pixels).

  • Optional: skew parameter s (usually zero for modern cameras).

Extrinsic parameters (camera pose):

  • Rotation matrix R (3×3) — orientation of camera relative to world.

  • Translation vector t (3×1) — position of camera in world coordinates.

The combination gives the full mapping from any 3D world point to its 2D image pixel coordinates, ignoring lens distortions. Distortions can be corrected separately. This model is the foundation for camera calibration, 3D reconstruction, augmented reality, and many other computer vision applications.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent