v9.1.1
Menu

Perspective Projection with Intrinsics

mediumFREE3D to 2D ProjectionsProjectionCV: Image Formation

Implement a perspective projection that maps 3D world points to 2D image coordinates using a camera's intrinsic matrix. This process is crucial in computer vision for understanding how 3D scenes are projected onto 2D images.

The intrinsic matrix, denoted as KK, encapsulates the camera's internal parameters, including focal lengths (fxf_x, fyf_y) in pixels and the principal point (cxc_x, cyc_y), which represents the optical center of the camera. The intrinsic matrix KK is given by K=(fx0cx0fycy001)K = \begin{pmatrix} f_x & 0 & c_x \\ 0 & f_y & c_y \\ 0 & 0 & 1 \end{pmatrix} To project a 3D point (XX, YY, ZZ) to a 2D image point, the following steps are involved:

  1. Perform perspective division by dividing the XX and YY coordinates by ZZ.
  2. Apply the intrinsic matrix KK to the normalized coordinates. The projection equation can be represented as p=K⋅[X/Z,Y/Z,1]T\mathbf{p} = K \cdot [X/Z, Y/Z, 1]^T.
K=(fx0cx0fycy001)K = \begin{pmatrix} f_x & 0 & c_x \\ 0 & f_y & c_y \\ 0 & 0 & 1 \end{pmatrix}

This technique is widely used in 3D reconstruction and image processing applications.

Example

Input
points_3d = [[0, 0, 10], [5, 5, 10]]
K = [[500, 0, 320], [0, 500, 240], [0, 0, 1]]
Output
[[320.0, 240.0], [570.0, 490.0]]
Reasoning
  • Inputs: points_3d holds two camera-frame points, (0,0,10)(0, 0, 10) and (5,5,10)(5, 5, 10), both at depth Z=10Z = 10. K has focal lengths fx=fy=500f_x = f_y = 500 pixels and principal point (cx,cy)=(320,240)(c_x, c_y) = (320, 240), the pixel where the optical axis hits the image.
  • Point 1: dividing by depth gives normalized coordinates (0/10, 0/10)=(0,0)(0/10,\ 0/10) = (0, 0). Multiplying KK by (0,0,1)T(0, 0, 1)^T leaves only the third column: u=500⋅0+320=320u = 500 \cdot 0 + 320 = 320, v=500⋅0+240=240v = 500 \cdot 0 + 240 = 240. A point on the optical axis always lands on the principal point.
  • Point 2: (5/10, 5/10)=(0.5,0.5)(5/10,\ 5/10) = (0.5, 0.5), so u=500⋅0.5+320=570u = 500 \cdot 0.5 + 320 = 570 and v=500⋅0.5+240=490v = 500 \cdot 0.5 + 240 = 490. The third component stays 11.
  • Output: one [u,v][u, v] pair per input point, rounded to 2 decimal places: [[320.0, 240.0], [570.0, 490.0]].
  • Notice that depth scales the offset: moving point 2 to Z=20Z = 20 halves its shift from the centre, giving (445,365)(445, 365).

Constraints

  • points_3d: List of [X, Y, Z] world points
  • K: 3×3 intrinsic matrix
  • Return: List of [u, v] pixel coordinates
  • Round to 2 decimal places

More from CV: Image Formation

solution.py

Test results

Sign in to run your code against the test cases.