Given pixel correspondences between 2 image viewpoints (xi<−>xi′).
We first normalize the pixel values by mean centering them and enforcing unit variance.
We create a constraint matrix A. Each correspondence gives one constraint. For 8-point algorithm we use 8 correspondences. Each row of constraint matrix is made by: [ui′uiui′viui′wivi′uivi′vivi′wiwi′uiwi′viwi′wi]
SVD(A) and find the vector in the null-space of A.
Project F to a rank 2 matrix. Udiag(d1,d2,d3)VT−>Udiag(d1,d2,0)VT
Transform solution to pixel space by denormalising the F matrix.
E is calculated from F using the formula E = K′TFK
E is projected to a rank 2 matrix using Udiag(d1,d2,d3)VT−>Udiag(dˉ,dˉ,0)VT
where, dˉ=2d1+2d2
7-point algorithm
Hydrant
ViewPoint 1
ViewPoint 2
Ball
ViewPoint 1
ViewPoint 2
Implementation
We first normalize the pixel values by mean centering them and enforcing unit variance.
We create a constraint matrix A. Each correspondence gives one constraint. For 7-point algorithm we use 7 correspondences. Each row of constraint matrix is made by: [ui′uiui′viui′wivi′uivi′vivi′wiwi′uiwi′viwi′wi]
SVD(A) and find 2 vector corresponding to the last 2 eigenvalues of A. General solution for F is λF1+(1−λ)F2
We enforce another constraint i.e. find λ. such that det(λF1+(1−λ)F2)=0. This gives us a 3-degree polynomial
Get all real roots. If multiple real roots find the one with the max number of inliers.
Given corresponding points from two images. The RANSAC implementation is a s follows:
Randomly select 7 / 8 points based on the algorithm to run.
Estimate F based on the selected points.
Calculate error by finding the distance of all points in pts2 to the epipolar line calculated by epipolar_line = pts1 @ F.T
Select points which are at a distance less than the set threshold. These points are considered inliers. In the code I have set the threshold to be 1 and max_iterations to be 10000.
Save the Fundamental matrix which gives the maximum inliers.
Q3 Triangulation
Point cloud reconstruction
Implementation
We use the Linear Triangulation method which is the direct analogue of DLT method.
Each image has a measurement x=PX and x′=P′X
These equatiions are combined to form AX=0 which is a linear in x.
For each image and for each point we can write x x (PX)=0
We get 2 equations from each image. Therefore from a correspondence we get 4 constraints. of the form