PIXELBANKv9.1.0
Menu

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:

Projecting point (0.1, 0.1, 1) through camera:

  1. Multiply K Γ— point: x' = 1000Γ—0.1 + 0Γ—0.1 + 320Γ—1 = 100 + 320 = 420 y' = 0Γ—0.1 + 1000Γ—0.1 + 240Γ—1 = 100 + 240 = 340 z' = 0Γ—0.1 + 0Γ—0.1 + 1Γ—1 = 1
  2. Normalize: u = 420/1 = 420, v = 340/1 = 340 Result: pixel (420, 340)

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
solution.py

Test Results

0/0
Run code to see test results.
Project 3D Point to Pixel - Medium | PixelBank