Triangulate 3D Point from Two Views
Given two camera projection matrices (3x4) and (3x4), and corresponding 2D points and in each image, triangulate the 3D point using the Direct Linear Transform (DLT) method.
Algorithm (DLT Triangulation):
For each 2D point and its projection matrix , we have:
This gives us a system of linear equations. From each view, we extract two independent equations:
where is the -th row of .
Build the matrix :
Solve via SVD of : the solution is the last column of (last row of ), converted from homogeneous coordinates.
Round each coordinate to 4 decimal places.
Example
P1 = [[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 1, 0]]
P2 = [[1, 0, 0, -1],
[0, 1, 0, 0],
[0, 0, 1, 0]]
x1 = [0.5, 0.5]
x2 = [0.0, 0.5][1.0, 1.0, 2.0]
- Inputs: ; is the same camera shifted one unit along . The point is seen at and .
- Rows of : with in both cameras, the four rows are , , and .
- Solving with : row 1 gives , row 2 gives , row 3 gives . Every solution is a multiple of ; the unit-length one found is .
- Homogeneous to Euclidean: dividing the first three entries by cancels both the scale and the sign, giving
[1.0, 1.0, 2.0]. - Notice that rows 2 and 4 are identical (the cameras differ only along , so agrees), so has rank 3 and the null space is exact. With noisy points, has full rank and you get the best least-squares fit instead.
Constraints
- P1, P2: 3x4 projection matrices as lists of lists
- x1, x2: 2D points as [u, v]
- Use numpy for SVD
- Return: [X, Y, Z] rounded to 4 decimal places
- The 3D point is in front of both cameras