Foundations of 3D Vision, Part 3 of 7. Previous: Part 2, homogeneous coordinates.
Part 2 ended with a toy camera matrix:
$$ \begin{bmatrix} f & 0 & 0 & 0 \\ 0 & f & 0 & 0 \\ 0 & 0 & 1 & 0 \end{bmatrix} $$It works, but it makes three assumptions no real camera meets. The camera sits at the origin of the world and looks straight down the Z axis. Image coordinates are measured from the center of the image. And $f$ is in the same units as the image.
In practice the camera stands somewhere in the room, pixels are counted from the top-left corner, and the sensor has its own size. Fixing all three gives the full pinhole camera model, which nearly every vision library, dataset and paper uses:
$$ \boxed{\;\tilde{\mathbf{u}} \;\sim\; K\,[\,R \mid \mathbf{t}\,]\,\tilde{\mathbf{X}}\;} $$$\tilde{\mathbf{X}} = (X, Y, Z, 1)$ is a world point and $\tilde{\mathbf{u}} = (u, v, 1)$ is its pixel, both homogeneous. The two pieces split the camera cleanly in two:
- Extrinsics $[R \mid \mathbf{t}]$: where the camera is and which way it points. They change every time you move the camera.
- Intrinsics $K$: what happens inside the camera, from the lens to the pixel grid. They stay fixed as long as you don’t zoom or refocus.
We’ll take them in the order a point meets them: world, then camera, then pixels.
Extrinsics: from the world to the camera#
A point in the world has coordinates $\mathbf{X}_w$ in some world frame: a room, a calibration board, a SLAM map. The camera wants the same point in its frame, $\mathbf{X}_c$, with the origin at the pinhole and Z pointing out of the lens. Getting there is a rotation followed by a translation:
$$ \mathbf{X}_c = R\,\mathbf{X}_w + \mathbf{t} $$$R$ is a $3 \times 3$ rotation (3 degrees of freedom) and $\mathbf{t}$ a 3-vector (3 more). In homogeneous form this is a single $3 \times 4$ matrix, $[R \mid \mathbf{t}]$, which is exactly what Part 2 promised: translation as a matrix product.
The rows of $R$ have a simple meaning: they are the camera’s own x, y and z axes, written in world coordinates. The third row is the direction the camera is looking.
One point confuses almost everyone the first time: $\mathbf{t}$ is not where the camera is. It is where the world origin appears in the camera’s frame. The camera’s position $C$ in the world is the point that maps to the camera origin, $R\,C + \mathbf{t} = 0$, so
$$ C = -R^\top \mathbf{t} $$Intrinsics: from the camera to pixels#
Now the point is in the camera frame, $(X_c, Y_c, Z_c)$. Divide by depth, as in Part 1, and you get the normalized image coordinates
$$ x = \frac{X_c}{Z_c}, \qquad y = \frac{Y_c}{Z_c} $$These are measured from the center of the image, in units where the focal length is 1. Pixels are not. They are counted from the top-left corner, with v growing downward, and their size depends on the sensor.

Getting from one to the other takes a scale and a shift:
$$ u = f_x\,x + c_x, \qquad v = f_y\,y + c_y $$which, as a matrix, is the intrinsic matrix
$$ K = \begin{bmatrix} f_x & s & c_x \\ 0 & f_y & c_y \\ 0 & 0 & 1 \end{bmatrix} $$Every entry has a physical meaning:
- $f_x, f_y$: focal length in pixels. It’s the lens’s focal length divided by the size of one pixel on the sensor. A 4 mm lens on a sensor with 2 µm pixels gives $f = 2000$ px. This is why the focal length in a camera file never looks like the number printed on the lens. $f_x$ and $f_y$ differ only if pixels are not square, and on modern sensors they are nearly equal.
- $c_x, c_y$: the principal point, where the optical axis meets the sensor. It’s usually near the image center, but never exactly there, because no lens is perfectly centered over its sensor.
- $s$: skew, nonzero only if the pixel grid’s axes aren’t perpendicular. For any camera you’re likely to meet, $s = 0$.
That’s 5 numbers, usually 4. Together with the 6 extrinsic ones that makes 11, and the full $3 \times 4$ camera matrix $P = K[R \mid \mathbf{t}]$ has exactly 11 degrees of freedom (12 entries, minus one for overall scale, which homogeneous coordinates ignore).
Intrinsics also fix the field of view. A ray at the right edge of an image $W$ pixels wide has $x = (W/2)/f_x$, so
$$ \text{FOV}_x = 2\arctan\!\left(\frac{W}{2 f_x}\right) $$A 1920-pixel-wide image with $f_x = 1000$ sees about 88°. Double $f_x$ and it drops to about 51°. That is zooming.
Zooming is not moving closer#
The split between $K$ and $[R \mid \mathbf{t}]$ isn’t just bookkeeping. They do different things to a picture.
Changing $K$ scales and shifts the image. Everything grows by the same factor, near and far alike, so the picture’s perspective is unchanged; you’re just cropping and enlarging. Changing $[R \mid \mathbf{t}]$ moves the pinhole, and things near the camera grow much faster than things far away.

In the middle and right images the front cube is the same size. In the zoomed one, the two back cubes grew with it. In the one where the camera walked closer, they barely changed, so they look much smaller next to the front cube. Filmmakers use exactly this, zooming in while moving the camera back, for the “dolly zoom” effect in Vertigo and Jaws.
Try it: building and using a real camera#
Here is a full camera, with the extrinsics built from a “look-at” (put the camera at $C$, point it at a target), the same way a graphics engine does. It uses OpenCV’s convention: x right, y down, z forward. To keep things simple, the world uses the same axes, so a camera at $Y = -2$ is above the scene.
import numpy as np
def to_h(p): return np.hstack([p, np.ones((len(p), 1))])
def from_h(p): return p[:, :-1] / p[:, -1:]
# Intrinsics: a 1920 x 1080 image, f = 1000 px, principal point at the center
W, H = 1920, 1080
K = np.array([[1000., 0., W / 2],
[ 0., 1000., H / 2],
[ 0., 0., 1.]])
print(2 * np.degrees(np.arctan(W / (2 * K[0, 0])))) # 87.7 degrees
# Extrinsics: camera at C, looking at the origin
def look_at(C, target, up=np.array([0., -1., 0.])):
z = target - C; z /= np.linalg.norm(z) # forward
x = np.cross(up, z); x /= np.linalg.norm(x) # right
y = np.cross(z, x) # down
R = np.stack([x, y, z]) # rows = camera axes in world coordinates
return R, -R @ C
C = np.array([3., -2., -4.])
R, t = look_at(C, np.zeros(3))
P = K @ np.hstack([R, t[:, None]]) # the 3x4 camera matrix
cube = np.array([[x, y, z] for x in (-.5, .5) for y in (-.5, .5) for z in (-.5, .5)])
print(from_h(to_h(cube) @ P.T).round()) # 8 pixel positions
print(from_h(to_h(np.zeros((1, 3))) @ P.T)) # [[960. 540.]] the target lands on the principal point
print(np.allclose(-R.T @ t, C)) # True: camera position from tThe world origin projects exactly to $(c_x, c_y)$, because the camera is looking straight at it.
Two more things you will need constantly.
Casting a ray through a pixel (the first step of every NeRF and every inverse renderer) runs the camera backwards. $K^{-1}$ turns a pixel into a direction in the camera frame, and $R^\top$ turns that into the world frame:
u, v = 1500, 300
d = R.T @ np.linalg.solve(K, [u, v, 1.])
d /= np.linalg.norm(d)
X = C + 5 * d # any point along the ray
print(from_h(to_h(X[None]) @ P.T)) # [[1500. 300.]] back where we startedSplitting a camera matrix back into $K$, $R$ and $\mathbf{t}$. If a method gives you only $P$, the left $3 \times 3$ block is $K R$: an upper-triangular matrix times a rotation. That is exactly what an RQ decomposition computes. It only needs a sign fix so the focal lengths come out positive:
from scipy.linalg import rq
K2, R2 = rq(P[:, :3])
S = np.diag(np.sign(np.diag(K2))) # make the diagonal of K positive
K2, R2 = K2 @ S, S @ R2
K2 /= K2[2, 2]
t2 = np.linalg.solve(K2, P[:, 3])
print(np.allclose(K2, K), np.allclose(R2, R), np.allclose(t2, t)) # True True TruePitfalls#
Most camera bugs aren’t math errors. They’re convention errors, and the result is a blank render or a scene upside down.
- World-to-camera or camera-to-world? The extrinsics above map world to camera. Many datasets store the inverse, the camera’s pose $[R^\top \mid C]$. The original NeRF datasets do this in their
transform_matrix. Check which one you have before you use it: the last column of a camera-to-world matrix is the camera position, and the last column of a world-to-camera matrix is not. - Axis conventions. OpenCV and COLMAP use x right, y down, z forward. OpenGL and Blender use x right, y up, and the camera looks down −z. Converting between them means flipping the y and z axes of the camera frame. Forget it and every point lands behind the camera.
- Resizing an image changes $K$. Halve the image and you must halve $f_x$, $f_y$, $c_x$ and $c_y$. Crop it and you must shift $c_x$, $c_y$. Data augmentation code that resizes images but not intrinsics is a classic silent bug.
- Pixel centers. Is pixel (0, 0)’s center at 0 or at 0.5? Conventions differ, and the half-pixel offset matters for anything precise.
- $K$ in millimetres. The focal length in a photo’s EXIF data is in millimetres. To use it you need the sensor size, and you must divide by pixel pitch, not just plug it in.
Where this shows up#
Every multi-view method starts here. COLMAP’s output, a NeRF dataset’s camera file and a SLAM system’s poses are all intrinsics plus extrinsics in one convention or another. In my own work on inverse rendering, recovering materials and lighting from images of hands holding objects, every pixel’s ray starts as $R^\top K^{-1}\tilde{\mathbf{u}}$.
There’s still one thing the pinhole model gets wrong: real lenses bend straight lines, especially near the edges of the image. And so far we’ve assumed $K$ is known.
Next, Part 4: lens distortion and calibration, or how to measure $K$ with a printed checkerboard.
Further reading#
- Richard Hartley and Andrew Zisserman, Multiple View Geometry in Computer Vision, Chapter 6 (camera models).
- Richard Szeliski, Computer Vision: Algorithms and Applications, Section 2.1 (free online at szeliski.org/Book).
- The OpenCV camera calibration docs, for the exact conventions most code uses.
