This report consists of 3 parts relating to analysis of
Camera projection matrix estimation is performed by first setting up a homogenous system of equations. SVD is used on the homogenous equation system to find out the camera calibration matrix
function M = calculate_projection_matrix( Points_2D, Points_3D )
homogenous_2D = [Points_2D ones(size(Points_2D,1),1)];
homogenous_3D = [Points_3D ones(size(Points_3D,1),1)];
A = [];
for row=1:size(Points_3D,1)
point_3d = homogenous_3D(row,:);
point_2d = homogenous_2D(row,:);
zero_cols = zeros(1,size(point_3d,2));
u_row = [point_3d zero_cols -point_2d(1,1)*point_3d];
v_row = [zero_cols point_3d -point_2d(1,2)*point_3d];
A = [A;u_row;v_row];
end
[U, S, V] = svd(A);
M = V(:,end);
M = reshape(M,[],3)';
end
0.4583 -0.2947 -0.0140 0.0040 -0.0509 -0.0546 -0.5411 -0.0524 0.1090 0.1783 -0.0443 0.5968
-1.5127 -2.3517 0.2826
Projections
Camera
0.0069 -0.0040 -0.0013 -0.8267 0.0015 0.0010 -0.0073 -0.5625 0.0000 0.0000 -0.0000 -0.0034
303.1000 307.1843 30.4217
Projections
Camera
function [ F_matrix ] = estimate_fundamental_matrix(Points_a,Points_b)
homogenous_a = [Points_a ones(size(Points_a,1),1)];
homogenous_b = [Points_b ones(size(Points_b,1),1)];
%normalization
c_uv = mean(Points_a);
s = std(Points_a);
s_matrix = [[s(1,1) 0 0];[0 s(1,2) 0];[0 0 1]];
c_matrix = [[1 0 -c_uv(1,1)]; [0 1 -c_uv(1,2)]; [0 0 1]];
T_a = s_matrix * c_matrix;
for point=1:size(homogenous_a,1)
homogenous_a(point,:) = T_a * transpose(homogenous_a(point,:));
end
c_uv = mean(Points_b);
s = std(Points_b);
s_matrix = [[s(1,1) 0 0];[0 s(1,2) 0];[0 0 1]];
c_matrix = [[1 0 -c_uv(1,1)]; [0 1 -c_uv(1,2)]; [0 0 1]];
T_b = s_matrix * c_matrix;
for point=1:size(homogenous_b,1)
homogenous_b(point,:) = T_a * transpose(homogenous_b(point,:));
end
%Build the matrix for equations
equation_matrix = [];
for row=1:size(homogenous_a,1)
point_a = homogenous_a(row,:);
point_b = homogenous_b(row,:);
combined_row = [point_b .* point_a(1,1), point_b .* point_a(1,2), point_b .* point_a(1,3)];
equation_matrix = [equation_matrix;combined_row];
end
[U, S, V] = svd(equation_matrix);
F = V(:,end);
F = reshape(F,[3 3])';
F = transpose(F); % visualization code assumed transpose version of the matrix compared to lecture slides
%Fix the rank
[U, S, V] = svd(F);
S(3,3) = 0;
F_matrix = U * S * transpose(V);
F_matrix = transpose(T_b) * F_matrix * T_a;
end
F_matrix =
-0.0000 0.0000 -0.0045
0.0000 -0.0000 0.0292
0.0001 -0.0467 1.9942
function [ Best_Fmatrix, inliers_a, inliers_b] = ransac_fundamental_matrix(matches_a, matches_b)
max_inliers = 0;
inliers_a = [];
inliers_b = [];
inliers = [];
for N=1:7000
random_indices = randperm(size(matches_a,1),8);
sampled_points_a = matches_a(random_indices,:);
sampled_points_b = matches_b(random_indices,:);
f_matrix = estimate_fundamental_matrix(sampled_points_a, sampled_points_b);
curr_inliers = 0;
curr_inliers_a = [];
curr_inliers_b = [];
% curr_inliers_with_err = [];
for point = 1:size(matches_a,1)
error = [matches_b(point,:) 1] * f_matrix * transpose([matches_a(point,:) 1]);
if abs(error) < 0.05
curr_inliers = curr_inliers + 1;
curr_inliers_a = [curr_inliers_a;matches_a(point,:)];
curr_inliers_b = [curr_inliers_b;matches_b(point,:)];
% curr_inliers_with_err = [curr_inliers_with_err; [matches_a(point,:) matches_b(point,:) abs(error)]];
end
end
if curr_inliers > max_inliers
Best_Fmatrix = f_matrix;
inliers_a = curr_inliers_a;
inliers_b = curr_inliers_b;
% inliers = curr_inliers_with_err;
max_inliers = curr_inliers;
end
end
% [d1,d2] = sort(inliers(:,5));
% inliers = inliers(d2,:);
% inliers_a = inliers(1:30,1:2);
% inliers_b = inliers(1:30,3:4);
% random_indices = randperm(size(inliers_a,1),min(30, size(inliers_a,1)));
% inliers_a = inliers_a(random_indices,:);
% inliers_b = inliers_b(random_indices,:);
end
Left : Raw co-ordinates, Right : With normalized co-ordinates
Bad Correspondences
Bad Epipolar geometry
Correspondences
Epipolar geometry
Correspondences
Epipolar geometry