v9.1.1
Menu

Project 3D Point to Pixel

mediumFREECamera CalibrationCalibrationCV: Structure from Motion and SLAM

Project a 3D point in camera coordinates to 2D pixel coordinates.

The projection of a 3D point to 2D uses the pinhole camera model:

(uv1)∼K(XYZ)\begin{pmatrix} u \\ v \\ 1 \end{pmatrix} \sim K \begin{pmatrix} X \\ Y \\ Z \end{pmatrix}

The "~" means equality up to scale. To get actual pixel coordinates:

  1. Multiply: (x′y′z′)=K⋅(XYZ)\begin{pmatrix} x' \\ y' \\ z' \end{pmatrix} = K \cdot \begin{pmatrix} X \\ Y \\ Z \end{pmatrix}

  2. Normalize by Z: u=x′/z′,v=y′/z′u = x'/z', \quad v = y'/z'

This implements perspective projection where distant objects appear smaller.

Example

Input
project_point([[1000,0,320],[0,1000,240],[0,0,1]], [0.1, 0.1, 1])
Output
[420.0, 340.0]
Reasoning
  • Inputs: KK holds the camera intrinsics: focal lengths fx=fy=1000f_x = f_y = 1000 pixels on the diagonal and the principal point (cx,cy)=(320,240)(c_x, c_y) = (320, 240) in the third column. The point (X,Y,Z)=(0.1,0.1,1)(X, Y, Z) = (0.1, 0.1, 1) is 11 unit in front of the lens.
  • Multiply by KK: x′=1000(0.1)+0(0.1)+320(1)=420x' = 1000(0.1) + 0(0.1) + 320(1) = 420, y′=0(0.1)+1000(0.1)+240(1)=340y' = 0(0.1) + 1000(0.1) + 240(1) = 340, z′=0(0.1)+0(0.1)+1(1)=1z' = 0(0.1) + 0(0.1) + 1(1) = 1.
  • Divide by depth: the bottom row of KK is (0,0,1)(0, 0, 1), so z′z' is the depth Z=1Z = 1, giving u=420/1=420u = 420/1 = 420 and v=340/1=340v = 340/1 = 340.
  • Output: [420.0, 340.0]: pixel column and row, rounded to 4 decimal places. Equivalently u=fxX/Z+cxu = f_x X/Z + c_x: the point lands 100100 pixels right of and 100100 below the principal point.
  • Notice: perspective means pushing the same point to Z=2Z = 2 halves that offset, giving (370,290)(370, 290). Any point on the axis, (0,0,Z)(0, 0, Z), projects to (320,240)(320, 240) at every depth.

Constraints

  • K: 3x3 intrinsic matrix
  • point_3d: [X, Y, Z] point in camera coordinates (Z > 0)
  • Return [u, v] pixel coordinates rounded to 4 decimal places

Learn this in

More from CV: Structure from Motion and SLAM

solution.py

Test results

Sign in to run your code against the test cases.