v9.1.1
Menu

Camera Projection Matrix

mediumFREE3D to 2D ProjectionsProjectionCV: Image Formation

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
  • Inputs: PP is a 3×43 \times 4 camera matrix and point is a 3D world point (X,Y,Z)=(10,20,5)(X, Y, Z) = (10, 20, 5). Here P=[ I∣0 ]P = [\,I \mid 0\,]: the identity block with a zero last column, i.e. focal length 1, no offset, camera at the origin.
  • Append a 1 to get the homogeneous point (10,20,5,1)(10, 20, 5, 1); that 1 is what lets the fourth column of PP act as a translation.
  • Each row of PP dotted with it gives one component: u=1⋅10+0⋅20+0⋅5+0⋅1=10u = 1\cdot10 + 0\cdot20 + 0\cdot5 + 0\cdot1 = 10, v=20v = 20, w=5w = 5.
  • Perspective divide: (u/w, v/w)=(10/5, 20/5)=(2.0, 4.0)(u/w,\ v/w) = (10/5,\ 20/5) = (2.0,\ 4.0), which is the output [2.0, 4.0], rounded to 4 decimal places.
  • Notice that ww ended up being the depth ZZ: points farther away get divided by more and land closer to the image centre. Doubling the point to (20,40,10)(20, 40, 10) projects to the same (2.0,4.0)(2.0, 4.0), since every point on one ray from the camera hits the same pixel.

Constraints

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

Learn this in

More from CV: Image Formation

solution.py

Test results

Sign in to run your code against the test cases.