PIXELBANKv9.1.0
Menu

Implement a function to calculate the reprojection error, a crucial component in bundle adjustment, which is a key technique in image alignment and stitching. The reprojection error measures the difference between the projected location of a 3D point and its observed location in a 2D image.

The concept of reprojection error is rooted in the pinhole camera model, where a 3D point X\mathbf{X} is transformed into a 2D point (u,v)(u, v) using the camera's rotation matrix RR and translation vector t\mathbf{t}. This transformation is followed by a perspective projection, which maps the 3D point to a 2D point using the camera's focal length ff.

To compute the reprojection error, the following steps are involved:

  1. Transform the 3D point using the rotation matrix and translation vector: Xβ€²=RX+t\mathbf{X}' = R\mathbf{X} + \mathbf{t}
  2. Project the transformed 3D point to a 2D point: (u,v)=(fXβ€²Zβ€²,fYβ€²Zβ€²)(u, v) = \left(f\frac{X'}{Z'}, f\frac{Y'}{Z'}\right)
  3. Calculate the error between the projected 2D point and the observed 2D point
e=(uβˆ’uobs)2+(vβˆ’vobs)2e = (u - u_{obs})^2 + (v - v_{obs})^2

This technique is widely used in computer vision applications, such as structure from motion and stereo vision.

Example:

Input:
X = [0, 0, 10]
observed = [0, 0]
R = [[1,0,0], [0,1,0], [0,0,1]]
t = [0, 0, 0]
focal = 1
Output:
0.0
Reasoning:
  1. Apply rotation (identity) and translation (zero): X' = RX + t = [0, 0, 10] + [0, 0, 0] = [0, 0, 10]

  2. Project to 2D: u = focal Γ— X' / Z' = 1 Γ— 0 / 10 = 0 v = focal Γ— Y' / Z' = 1 Γ— 0 / 10 = 0 Projected: (0, 0)

  3. Compute error: e = (0 - 0)Β² + (0 - 0)Β² = 0

The 3D point projects exactly to the observed location.

Constraints:

  • X is 3D point [X, Y, Z]
  • observed is 2D point [u, v]
  • R is 3x3 rotation matrix (use identity for simplicity)
  • t is translation [tx, ty, tz]
  • focal is focal length
  • Return squared reprojection error rounded to 4 decimal places
πŸ”’

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.