Algorithm Search⌘K

Definitionintro

Camera intrinsic matrix

Also called calibration matrix, K matrix.

The upper triangular 3 by 3 matrix of focal lengths, skew and principal point that maps camera coordinates of a ray to pixel coordinates.

The camera intrinsic matrix KK is the 3×33 \times 3 upper triangular matrix that turns the direction of a ray, given in the frame of the camera, into the pixel where that ray meets the image. It holds the five internal parameters of a pinhole camera: two focal lengths in pixels, a skew and the two coordinates of the principal point. It does not hold the position or the turn of the camera, which are the extrinsic parameters, and it does not hold lens distortion. Together the two give the camera projection matrix P=K[R∣t]P = K [R \mid t]. The graphics page pinhole camera model describes the same camera, but it looks along −w-w; here the camera looks along +Z+Z.

Definition

Camera frame. The camera frame has its origin at the center of projection, XX to the right, YY down and ZZ forward along the optical axis. A point Xc=(X,Y,Z)X_c = (X, Y, Z) is in front of the camera if Z>0Z > 0. Its normalized image coordinates are xn=(X/Z,Y/Z)x_n = (X / Z, Y / Z), the point where its ray meets the plane Z=1Z = 1.

Pixels. An image has WW columns and HH rows. The pixel (u,v)(u, v) is in column uu (to the right) and row vv (down), and the origin is the top left pixel. We put the center of pixel (u,v)(u, v) at the point (u,v)(u, v), as Hartley and Zisserman (HZ) and OpenCV do.

The matrix. The intrinsic matrix is

K=(fxscx0fycy001),fx>0,  fy>0,K = \begin{pmatrix} f_x & s & c_x \\ 0 & f_y & c_y \\ 0 & 0 & 1 \end{pmatrix}, \qquad f_x > 0, \; f_y > 0,

and it maps a point in the camera frame to its pixel by

(uv1)∼K(XYZ),u=fxXZ+sYZ+cx,v=fyYZ+cy.\begin{pmatrix} u \\ v \\ 1 \end{pmatrix} \sim K \begin{pmatrix} X \\ Y \\ Z \end{pmatrix}, \qquad u = f_x \frac{X}{Z} + s \frac{Y}{Z} + c_x, \quad v = f_y \frac{Y}{Z} + c_y.

The symbol ∼\sim means equal up to a nonzero scale, here the scale ZZ.

  • fx=fmxf_x = f m_x and fy=fmyf_y = f m_y are the focal length in pixels along the rows and the columns: ff is the distance from the center to the image plane, and mxm_x, mym_y are the numbers of pixels per unit length on the sensor. If the pixels are square, fx=fyf_x = f_y. The ratio fy/fxf_y / f_x is the aspect ratio.
  • (cx,cy)(c_x, c_y) is the principal point, the pixel where the optical axis meets the image. It is near the image center, but it is not the image center.
  • ss is the skew. It is not zero only if the axes of the pixel grid are not perpendicular. For almost all modern cameras s=0s = 0, and many calibration programs fix it to 0.

So KK has 5 degrees of freedom, 4 with zero skew and 3 with zero skew and square pixels. Any upper triangular 3×33 \times 3 matrix with a positive diagonal is a multiple of exactly one such KK: divide it by its last entry.

The inverse. KK is invertible, with

K−1=(1/fx−s/(fxfy)(scy−cxfy)/(fxfy)01/fy−cy/fy001).K^{-1} = \begin{pmatrix} 1/f_x & -s/(f_x f_y) & (s c_y - c_x f_y)/(f_x f_y) \\ 0 & 1/f_y & -c_y / f_y \\ 0 & 0 & 1 \end{pmatrix}.

For a pixel x=(u,v,1)Tx = (u, v, 1)^{\mathsf T}, the vector K−1xK^{-1} x is the direction of the ray that the pixel sees, in the camera frame. Its last entry is 1, and its first two entries are xnx_n. So KK and K−1K^{-1} convert between pixels and normalized coordinates. Lens distortion acts on normalized coordinates: project, distort, then apply KK (see Brown-Conrady distortion model).

Angles between rays. The angle θ\theta between the rays of two pixels x1x_1 and x2x_2 is

cos⁡θ=x1Tωx2x1Tωx1x2Tωx2,ω=K−TK−1.\cos\theta = \frac{x_1^{\mathsf T} \omega x_2}{\sqrt{x_1^{\mathsf T} \omega x_1}\sqrt{x_2^{\mathsf T} \omega x_2}}, \qquad \omega = K^{-\mathsf T} K^{-1}.

This is the angle between K−1x1K^{-1} x_1 and K−1x2K^{-1} x_2. The matrix ω\omega is the image of the absolute conic, and a known KK is what makes angles measurable in an image.

Examples and non-examples

A typical camera. Let fx=fy=800f_x = f_y = 800, s=0s = 0 and (cx,cy)=(320,240)(c_x, c_y) = (320, 240), for an image of 640×480640 \times 480 pixels. The point Xc=(0.5,−0.25,2)X_c = (0.5, -0.25, 2) has xn=(0.25,−0.125)x_n = (0.25, -0.125), so

u=800⋅0.25+320=520,v=800⋅(−0.125)+240=140.u = 800 \cdot 0.25 + 320 = 520, \qquad v = 800 \cdot (-0.125) + 240 = 140.

The pixel (520,140)(520, 140) is to the right of and above the principal point, because X>0X > 0 and Y<0Y < 0. Back the other way, K−1(520,140,1)T=(0.25,−0.125,1)K^{-1} (520, 140, 1)^{\mathsf T} = (0.25, -0.125, 1), and the point at depth 2 on this ray is XcX_c again.

Field of view. If the principal point is at the image center, the horizontal field of view is 2arctan⁡(W/(2fx))2 \arctan(W / (2 f_x)). Here 2arctan⁡(320/800)=2arctan⁡0.4≈43.602 \arctan(320 / 800) = 2 \arctan 0.4 \approx 43.60 degrees.

The image center depends on the pixel convention. With pixel centers at integer points, the image of W=640W = 640 columns covers u∈[−0.5,639.5]u \in [-0.5, 639.5], and its center is u=319.5u = 319.5. With the convention of the graphics pixel page and of COLMAP, where the center of pixel uu is at u+0.5u + 0.5, the same image covers [0,640][0, 640] and its center is 320. So a cxc_x from such a source must be lowered by 0.5 before it is used with the formulas on this page.

Scaling the image. If the image is shrunk by a factor 2 in each direction, the new pixel u′u' covers the old coordinates [2u′−0.5,2u′+1.5][2u' - 0.5, 2u' + 1.5], so an old coordinate xx becomes u′=x/2−0.25u' = x / 2 - 0.25. Then fx′=fx/2f_x' = f_x / 2 and cx′=cx/2−0.25c_x' = c_x / 2 - 0.25: for the camera above, fx′=400f_x' = 400 and cx′=159.75c_x' = 159.75. The shift of −0.25-0.25 disappears in the u+0.5u + 0.5 convention, and forgetting it is a common source of small biases.

Non-examples.

  • A matrix with fy<0f_y < 0, which some graphics code uses for YY up. It is a valid camera, but not an intrinsic matrix in this convention: the pages of this area keep fx,fy>0f_x, f_y > 0 and put the flip in the axes.
  • A lower triangular matrix, or one whose last row is not a multiple of (0,0,1)(0, 0, 1). The decomposition of PP into KK and RR relies on the upper triangular form.
  • The 4×44 \times 4 projection matrix of OpenGL. It maps to clip coordinates, keeps a depth value for the z-buffer, and is followed by the viewport transform. Its first two rows hold the same focal lengths and principal point, in another scale.
  • A distortion model. Radial and tangential distortion are not linear in homogeneous coordinates, so no 3×33 \times 3 matrix can hold them.

References

  1. Richard Hartley and Andrew Zisserman, Multiple View Geometry in Computer Vision, second edition, Cambridge University Press, 2004, Section 6.1, Finite cameras (the camera calibration matrix, its five parameters, and the meaning of each one)
  2. Richard Szeliski, Computer Vision, Algorithms and Applications, second edition, Springer, 2022, Chapter 2, Image formation (the calibration matrix and the camera intrinsics)
  3. Peter Sturm, Srikumar Ramalingam, Jean-Philippe Tardif, Simone Gasparini and Joao Barreto, Camera models and fundamental concepts used in geometric computer vision, Foundations and Trends in Computer Graphics and Vision 6(1-2), 2011, 1-183, the part on central perspective cameras and their intrinsic parameters

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/08K0VT/text.yaml