PIXELBANKv8.2.1
Menu

Camera Projection Matrix

Implement a camera projection matrix to transform 3D world coordinates into 2D image coordinates. This process is crucial in computer vision for understanding how 3D scenes are mapped onto 2D images.

The concept of 3D to 2D projection involves representing a 3D point in a 2D space, which is essential for image formation. The projection matrix PP plays a key role in this transformation, mapping 3D world coordinates (X,Y,Z)(X, Y, Z) to 2D image coordinates (u,v)(u, v).

Here are the steps to apply the projection matrix:

  1. Represent the 3D point as a homogeneous coordinate vector.
  2. Multiply the projection matrix PP by the 3D point.
  3. Obtain the projected 2D coordinates.
(uvw)=P(XYZ1)\begin{pmatrix} u \\ v \\ w \end{pmatrix} = P \cdot \begin{pmatrix} X \\ Y \\ Z \\ 1 \end{pmatrix}

The final 2D coordinates are given by (u/w,v/w)(u/w, v/w). This technique is widely used in image processing and computer vision applications.

Example:

Input:
project([[1,0,0,0],[0,1,0,0],[0,0,1,0]], [10, 20, 5])
Output:
[2.0, 4.0]
Reasoning:
  • First, write the 3D point in homogeneous form: [X,Y,Z,1]=[10,20,5,1][X, Y, Z, 1] = [10, 20, 5, 1].
  • Multiply by the projection matrix PP:
    • u=110+020+05+01=10u = 1\cdot10 + 0\cdot20 + 0\cdot5 + 0\cdot1 = 10
    • v=010+120+05+01=20v = 0\cdot10 + 1\cdot20 + 0\cdot5 + 0\cdot1 = 20
    • w=010+020+15+01=5w = 0\cdot10 + 0\cdot20 + 1\cdot5 + 0\cdot1 = 5
  • Convert to 2D by dividing by ww: (u/w,v/w)=(10/5,20/5)=(2.0,4.0)(u/w, v/w) = (10/5, 20/5) = (2.0, 4.0).
  • Therefore, the final output is [2.0, 4.0].

Constraints:

  • P is a 3×4 matrix
  • point is [X, Y, Z]
  • Return [x, y] rounded to 4 decimal places
Editor

Test Results

0/0
Run code to see test results.