v9.1.1
Menu

Pinhole Camera Intrinsic Projection

mediumFREECamera modelGeometry, Linear AlgebraComputer Vision 1

Given a 3D point in camera coordinates and a camera intrinsic matrix KK, compute the projected 2D pixel coordinates using the pinhole camera model.

The intrinsic matrix KK has the form:

K=[fxscx0fycy001]K = \begin{bmatrix} f_x & s & c_x \\ 0 & f_y & c_y \\ 0 & 0 & 1 \end{bmatrix}

Where fx,fyf_x, f_y are focal lengths, (cx,cy)(c_x, c_y) is the principal point, and ss is the skew (often 00, but it may be nonzero, so apply the full matrix).

The projection formula is:

[uv1]=1ZcK[XcYcZc]\begin{bmatrix} u \\ v \\ 1 \end{bmatrix} = \frac{1}{Z_c} K \begin{bmatrix} X_c \\ Y_c \\ Z_c \end{bmatrix}

Return the 2D pixel coordinates [u,v][u, v] rounded to 4 decimal places.

Example

Input
print(pinhole_projection([[800.0, 0.0, 320.0], [0.0, 800.0, 240.0], [0.0, 0.0, 1.0]], [10.0, 20.0, 5.0]))
Output
[1920.0, 3440.0]
Reasoning
  • Inputs: intrinsic_lambda is the 3×33 \times 3 matrix KK with fx=fy=800f_x = f_y = 800, principal point (cx,cy)=(320,240)(c_x, c_y) = (320, 240) and zero skew. point_w_prime is the camera-frame point (Xc,Yc,Zc)=(10,20,5)(X_c, Y_c, Z_c) = (10, 20, 5), so it sits 5 units in front of the camera.
  • Perspective: dividing by depth puts the point on the plane Z=1Z = 1: (105,205,1)=(2,4,1)\left(\tfrac{10}{5}, \tfrac{20}{5}, 1\right) = (2, 4, 1). Points twice as far away would land half as far from the optical axis.
  • Intrinsics: KK scales those normalized coordinates into pixels and shifts them to the principal point: u=800⋅2+0⋅4+320=1920u = 800 \cdot 2 + 0 \cdot 4 + 320 = 1920, v=800⋅4+240=3440v = 800 \cdot 4 + 240 = 3440. The third row gives 11, confirming the homogeneous form.
  • Output: the pixel pair [1920.0, 3440.0], floats rounded to 4 decimal places.
  • Notice the result lies far outside a 640×480640 \times 480 image: the projection never clips, it just maps the ray. With a nonzero skew ss, uu would also pick up ss times the normalized yy.

Constraints

  • The 3D point [X_c, Y_c, Z_c] is in camera coordinates with depth Z_c > 0
  • K (passed as intrinsic_lambda) is a valid 3x3 intrinsic matrix
  • All inputs are floating-point numbers
  • Output must be rounded to 4 decimal places

Learn this in

More from Computer Vision 1

solution.py

Test results

Sign in to run your code against the test cases.