Multi-View Triangulation Error
Compute the total reprojection error for a 3D point observed in multiple camera views.
In Structure from Motion (SfM), we triangulate 3D points from multiple 2D observations. The quality of a triangulated point is measured by its reprojection error - how well it projects back to the observed 2D locations.
For each view i, the reprojection error is: eiβ=β£β£Ο(Kiβ,Riβ,tiβ,X)βpiββ£β£2
where Ο projects the 3D point X to 2D, and piβ is the observed 2D point.
Total error is the sum across all views: Etotalβ=βiβeiβ=βiβ((uiββu^iβ)2+(viββv^iβ)2)
Lower error indicates better triangulation.
Example:
triangulation_error([0, 0, 10], [([[1000,0,320],[0,1000,240],[0,0,1]], [[1,0,0],[0,1,0],[0,0,1]], [0,0,0], [320, 240])])
0.0
Point at (0,0,10) with identity pose:
- Transform to camera: X_cam = IΓ[0,0,10] + [0,0,0] = [0,0,10]
- Project: u = (1000Γ0 + 320Γ10)/10 = 320 v = (1000Γ0 + 240Γ10)/10 = 240
- Error: (320-320)Β² + (240-240)Β² = 0 Perfect reprojection means the 3D point is correct.
Constraints:
- point_3d: [X, Y, Z] in world coordinates
- observations: list of (K, R, t, pixel) tuples for each view
- Return total squared reprojection error rounded to 4 decimal places
More from CV: Structure from Motion and SLAM
To solve this problem, you just need to project a 3D point into each camera, compare with the observed 2D point, and sum the squared pixel errors over all views.
1. Background Knowledge
In Structure from Motion (SfM), we estimate both camera poses and 3D scene points from multiple 2D images. Each camera view has known intrinsics Kiβ (focal length, principal point, etc.) and extrinsics (Riβ,tiβ) describing its position and orientation relative to a world coordinate system. A 3D point X in world coordinates can be projected into image i via the camera projection model.
The reprojection error measures how consistent a 3D point is with its observed 2D measurements. For each view i, we project X into the image to get a predicted pixel p^βiβ=(\hat{u}iβ,\hat{v}iβ), and compare it with the detected feature point piβ=(uiβ,viβ). The squared Euclidean distance β₯\hat{p}iββpiββ₯2 is the per-view error. Summing these over all views gives the total reprojection error, which is the standard objective minimized in bundle adjustment.
2. Algorithm / General Approach
The pattern is:
- For each camera:
- Transform the 3D point from world coordinates into the camera coordinate frame.
- Apply the pinhole projection model with intrinsics Kiβ to get image coordinates.
- Convert from homogeneous to 2D pixel coordinates.
- Compute the squared pixel error between predicted and observed 2D points.
- Accumulate (sum) these squared errors over all views.
This is a straightforward per-view loop with a constant amount of math per view.
3. Step-by-Step Strategy
Assume you are given:
- 3D point X=(X,Y,Z) in world coordinates (often as a 3D vector).
- For each view i:
- Intrinsic matrix Kiβ (3Γ3).
- Rotation Riβ (3Γ3) and translation tiβ (3Γ1).
- Observed pixel piβ=(uiβ,viβ).
Steps:
- Initialize total error
total_error = 0.0
- Loop over each view i:
- Convert X to a column vector (or use your vector type).
- Transform to camera coordinates
Let Xcamβ=(Xcβ,Ycβ,Zcβ).
- Project using intrinsics
- First to homogeneous image coordinates:
Let ximghomβ=(xβ²,yβ²,zβ²).
- Then to 2D pixel coordinates:
- Compute per-view squared reprojection error
du = u_i - u_hat
dv = v_i - v_hat
e_i = du*du + dv*dv
total_error += e_i
- Return total error
return total_error
That directly implements:
Etotalβ=iβββ₯Ο(Kiβ,Riβ,tiβ,X)βpiββ₯24. Common Pitfalls
-
Homogeneous division mistakes:
-
Forgetting to divide by the third coordinate zβ², or dividing by Zcβ before multiplying by Kiβ.
-
Mixing up where to apply intrinsics; correct sequence is: world β camera β multiply by Kiβ β divide by homogeneous depth.
-
Coordinate convention mismatches:
-
Ensure that Riβ,tiβ transform world coordinates to camera coordinates. If they are stored as camera-to-world, you must invert them.
-
Be consistent with units (pixels vs normalized coordinates). If intrinsics are applied, the result should be in pixel coordinates.
-
Sign / depth issues:
-
If Zcββ€0 (point behind the camera), the projection is not valid; the problem may specify how to handle such cases. In simple coding tasks, such cases may not appear, but be aware.
-
Matrix shapes and ordering:
-
Ensure correct dimensions (3Γ3 times 3Γ1, etc.).
-
Avoid mixing row-major vs column-major conventions; be consistent across your math and library.
5. Time & Space Complexity
Let N be the number of views observing this point.
-
Time complexity:
-
Each view does a constant number of matrixβvector multiplications and scalar operations.
-
Overall: O(N).
-
Space complexity:
-
You only keep a running sum and temporary 3D/2D vectors.
-
Overall: O(1) additional space (beyond the given inputs).