v9.1.1
Menu

Reprojection Error

mediumPROBundle AdjustmentOptimizationCV: Image Alignment and Stitching

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
  • Inputs: X is a 3D point (0,0,10)(0, 0, 10) in world coordinates, observed is the pixel where it was actually seen, (0,0)(0, 0), R is the 3×33 \times 3 identity (no rotation), t is the zero translation, and focal is f=1f = 1.
  • Into camera coordinates: X′=RX+t=(0,0,10)+(0,0,0)=(0,0,10)\mathbf{X}' = R\mathbf{X} + \mathbf{t} = (0, 0, 10) + (0, 0, 0) = (0, 0, 10). The camera frame equals the world frame, so the point lies 10 units down the optical axis.
  • Perspective projection: u=fX′Z′=1⋅010=0u = f \frac{X'}{Z'} = 1 \cdot \frac{0}{10} = 0 and v=fY′Z′=1⋅010=0v = f \frac{Y'}{Z'} = 1 \cdot \frac{0}{10} = 0, so the predicted pixel is (0,0)(0, 0).
  • Error: e=(0−0)2+(0−0)2=0e = (0 - 0)^2 + (0 - 0)^2 = 0, rounded to 4 decimal places gives 0.0.
  • Notice: the error is a squared distance in the image plane, not in 3D. Depth is divided out, so (10,10,10)(10, 10, 10) projects to (1,1)(1, 1): observed at (1,1)(1, 1) it scores 00, but observed at (0,0)(0, 0) it scores 12+12=21^2 + 1^2 = 2.

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

Learn this in

More from CV: Image Alignment and Stitching

PRO

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

Sign in to run your code against the test cases.