C.W.K.
Stream
Lesson 01 of 05 · published

The Pinhole Camera

~13 min · pinhole, projection, perspective, forward-model

Level 0Blank Page
0 XP0/35 lessons0/12 achievements
0/100 XP to next level100 XP to go0% complete
"A camera is a machine for throwing away depth. To recover it, you first have to understand exactly how it was lost."

A Camera Is a Flattening Machine

A photograph is a 3-D world crushed onto a 2-D plane, and the crushing follows a rule simple enough to write on a napkin: the pinhole camera model. Imagine light from the scene passing through one tiny hole onto a flat sensor behind it. Each 3-D point travels in a straight line through that hole and lands at exactly one pixel. That's the entire model — and because it's exact, it can be run backward.

Divide by Depth

The one operation that matters is dividing by depth. Take a point the camera sees at position (X, Y, Z), where Z is how far away it is. Its pixel is x = focal · X / Z and y = focal · Y / Z, shifted to the image center. That little / Z is the whole soul of perspective: double a point's distance and it maps twice as close to the center and appears half as big. Parallel rails converge because their sideways offset stays fixed while Z grows. A nose near the lens looms because its Z is small. Every perspective effect you've ever drawn is that single divide.

Intrinsics and Extrinsics

The full projection has two halves. Extrinsics — a rotation R and translation t — describe where the head sits relative to the camera; this is the pose Loomis wants. Intrinsics — the focal length and the principal point — describe the camera itself. A pixel is the 3-D point pushed first through the extrinsics (into the camera's frame) and then through the intrinsics (the divide-by-depth). Keep the two halves separate in your head; the camera solve is really just 'hold intrinsics roughly fixed, solve for the extrinsics.'

This Is the Forward Model

Everything in this lesson runs 3-D-to-pixel — the forward direction, the easy one. Loomis lives in the inverse: it has the pixels and wants R back. But the inverse is only tractable because the forward model is this clean and this exact. Understand projection going forward and solvePnP, next lesson, stops being a black box and becomes 'the thing that undoes this divide.'

Code

3-D point to pixel, the whole forward model·python
import numpy as np

def project(point_3d, R, t, focal, center):
    # EXTRINSICS: put the point into the camera's frame (where the head sits)
    cam = R @ point_3d + t            # (X, Y, Z) as the camera sees it

    # INTRINSICS: the pinhole divide-by-depth (the camera itself)
    x = focal * cam[0] / cam[2] + center[0]   # <-- divide by Z => perspective
    y = focal * cam[1] / cam[2] + center[1]
    return np.array([x, y])           # a pixel

# Foreshortening, converging rails, a looming nose -- ALL of it is that
# single `/ cam[2]`. Delete the divide and you get flat orthographic projection.

External links

Exercise

Hold a pen at arm's length, one eye closed, and slowly bring it toward your open eye. It appears to grow. Nothing about the pen changed — only its Z (distance) shrank, and the pixel size goes as 1/Z. Now explain, in that same 1/Z language, why railway tracks appear to meet at the horizon.
Hint
The pen's real size is fixed; its apparent size is size/Z, so halving Z doubles the apparent size. For the rails, their fixed sideways separation is divided by an ever-growing Z as they recede, so the projected gap shrinks toward zero — they 'meet' at the point where Z is effectively infinite. Same divide, two everyday illusions.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.