HW3: 3D reconstruction

Q1: 8-point and 7-point algorithm

(A1) F matrix using 8-point algorithm

Description

Normalize the Coordinates

Compute a similarity transformation \(T_1\) and \(T_2\) such that the centroid of the points is moved to the origin, and the maximum distance from the origin is scaled to \(\sqrt{2}\).

Formulate the Equation

For each pair of correspondences \((x_1,y_1,1)\) and \((x_2,y_2,1)\), expanding the equation \((x_2,y_2,1)^T\mathbf{F}(x_1,y_1,1) = 0\), we obtain the following expressions:

\[ x1x2F_{11}+x2y1F_{12}+x2F_{13}+y2x1F_{21}+y1y2F_{22}+y2F_{23}+x1F_{31}+y1F_{32}+F_{33}=0 \]

Combining these equations results in a linear equation for \(\mathbf{F}\).

Solve for F

Using Singular Value Decomposition (SVD) to solve for \(\mathbf{F}\), the final result is given by \(\mathbf{T_2}^T \mathbf{F} \mathbf{T_1}\).

Epipolar lines

Viewpoint 1 (Points) Viewpoint 2 (Epipolar Lines)

(A2) E matrix using 8-point algorithm

Using the formula \(\mathbf{E} = \mathbf{K}_2^T \mathbf{F} \mathbf{K}_1\), we get the estimated \(\mathbf{E}\) as \[ \begin{bmatrix} -0.41524274 & -8.81748894 & -2.15055808 \\ -1.3803559 & 0.79067134 & 69.08265036 \\ -3.58890876 & -68.47438701 & 1. \end{bmatrix} \]

(B) 7-point algorithm

Description

Formulate the Equation

After formulating the equation using the eight-point algorithm, we apply Singular Value Decomposition (SVD) to obtain the solution space, represented as \(<\mathbf{M}_1, \mathbf{M}_2>\). The general solution of the linear equation can be expressed as \(\lambda \mathbf{M}_1 + (1 - \lambda) \mathbf{M}_2\). Next, we use the fact that the fundamental matrix has rank two, and solve the equation \(\det(\lambda \mathbf{M}_1 + (1 - \lambda) \mathbf{M}_2) = 0\) using np.polynomial.polynomial.polyroots. If there are three real solutions, we must select the correct one. For this assignment, we assume the epipoles lie outside the image, which helps identify the correct solution.

Epipolar lines

Viewpoint 1 (Points) Viewpoint 2 (Epipolar Lines)

Q2: RANSAC with 7-point and 8-point algorithm

Description

We sample the minimum number of points required to estimate \(\mathbf{F}\) using the RANSAC algorithm. To determine if a correspondence pair is an inlier, we compute the sum of squared distances between the corresponding points and their estimated epipolar lines. If the error falls below a predefined threshold, the pair is classified as an inlier.

Output Images

Viewpoint 1 (Points) Viewpoint 2 (Epipolar Lines) % of inliers vs. # of iterations

Q3: Triangulation

Description

For a 3D point \(\mathbf{x} = (x, y, z)\) with its projection on the image plane at ((u, v)), we have the constraint \((\mathbf{P} (x, y, z)^T) \times (u, v)^T = 0\). This allows us to formulate a \(4 \times 3\) matrix \(\mathbf{A}\) such that \(\mathbf{A} \mathbf{x} = 0\). The solution to this linear system can then be obtained using singular value decomposition (SVD).

Output Point Cloud

Q4: Reconstruct your own scene!

Multi-view images Output

Q5: Bonus 1 - Fundamental matrix estimation on your own images.

Description

We use cv2.ORB_create to extract features and cv2.BFMatcher to compute potential matches. Then, we use the RANSAC algorithm implemented in q2 to compute \(\mathbf{F}\)

Epipolar lines

Viewpoint 1 (Points) Viewpoint 2 (Epipolar Lines)