Project 3 / Camera Calibration and Fundamental Matrix Estimation with RANSAC

Projection Matrix and Camera Center

Calculating the projection matrix requires solving a set of homogenous equations. To set up these equations I filled an array with:

[X1 Y1 Z1 0 0 0 -u1*X1 -u1*Y1 -u1*Z1
0 0 0 X1 Y1 Z1 -v1*X1 -v1*Y1 -v1*Z1
. . . . . . . . .
Xn Yn Zn 0 0 0 -un*Xn -un*Yn -un*Zn
0 0 0 Xn Yn Zn -un*Xn -un*Yn -un*Zn]

Projected vs. Actual

Where elements are X,Y and Z are 3D coordinates and u,v are 2D coordinates. After setting up the matrix, single value decomposition is used to solve the equations and obtain our projection matrix. The projected points appear reasonably accurate when compared to the actual points.

The camera center is calculated using the projection matrix. Matrix Q is created by slicing all rows and three columns of the proejction matrix. M4 is a slice of the end column of the projection matrix. The center is then computed using this operation: inv(-Q)*M4

Estimation of Fundamental Matrix

Estimaion of the fundamental matrix involves solving a set of equations wiht elements from two sets of 2D coordinates. The process for this involved filling an array with the appropriate elements to form a system of equations. Then using single value decomposition on the equation system to solve and obtain the fundamental matrix. In this function the points are normalized by linear transform. In order to construct the transformation matrix I implemented a function called get_T_mat. In this fuuntion I take the average or the points and use this find the sum of square differences of points. I average the result and use this to build the transformation matrix. The points are multiplied by this transformation matrix to give us normalized points. These normalized points are used in place of the original 2D image coordinates and used to contruct our set equations mentioned above.


%Transformation Matrix
T_mat = [sqrt(2)/mean_SD 0 -sqrt(2)/mean_SD*meanP(1);...
         0 sqrt(2)/mean_SD -sqrt(2)/mean_SD*meanP(2);...
         0 0 1];

Image A

Image B

Image A and Image B show the epipolar lines between the corresponding image pairs and using the fundamental matrix.

RANSAC & Results

For this function I randomly sample eight points from the matches. A fundamental matrix is created using those eight points. Then for each point correspondence in our matches the matches are saved as inliers if point A * F_matrix * point B' is below a certain threshold. This process is repeated N times and the best fundamental matrix is selected based on which one produces the highest number of inliers. The threshold can prove somewhat troublsome if it is too strict. A restrictive threshold may give us a low amount of inliers and may elminate some good matches. Mount Rushmore and Notre Dame often give good results when the function is run on them. The Gaudi pair proves to be a bit more difficult. The point normalization for the fundamental matrix appeared to help with this a little.

Rushmore Epipolar A

Mountain View

Rushmore Epipolar B

Mountain View

Rushmore Correspondence

Mountain View

Notre Dame Epipolar A

Mountain View

Notre Dame Epipolar B

Mountain View

Notre Dame Correspondence

Mountain View

Gaudi Epipolar A

Mountain View

Gaudi Epipolar B

Mountain View

Gaudi Correspondence

Mountain View