I have to reconstruct the 3D position of some visible features, which are visible on two images taken from a car. The photos have different positions and angles. I was able to derive the matrix K
from the first image because the requirement of the project asked for the camera calibration matrix of that specific image.
For the 3D reconstruction, I have to follow these steps:
- Find the matching point, and estimate the fundamental matrix
F
. - Since I don't have any information about the
P2
(projection matrix of the second image), I have to use the Essential matrix to be able to retrieve the matrixR
andT
for the second camera. - Executing triangulation and building the 3D position.
%% finding fundomental metrix
matched_points_image1 = [x_i_1, y_i_1];
matched_points_image2 = [x_i_2, y_i_2];
[F, inliers] = estimateFundamentalMatrix(matched_points_image1,matched_points_image2,'NumTrials',2000);
F = [-0.0000 -0.0000 0.0028;
0.0001 -0.0000 -0.0038;
-0.0050 -0.0060 1.0000];
%% Finding the essential metrix
fprintf("Finding the essential metrics because we don't know the R and T between two cameras whose took the pictures...\n")
K1 = [ 1.1137 0 1.2254;
0 1.6541 0.0428;
0 0 0.0001];
E = K1'*F*K1;
%putting the first camera as world reference
P1 = K1*eye(3,4);
%Estimation of P2 based on svd decomposition of E
[U,S,V] = svd(E);
W = [0 1 0;-1 0 0;0 0 1];
R_2_positive = U*W'*V';
R_2_negative = U*W*V';
%since there are two rotation matrices, for each of them there are two
%possible translation matrice. [t]×= ±E12R
t_2_1_positive = E*(R_2_positive)';
t_2_2_positive = E'*(R_2_positive)';
t_2_1_negative = E*(R_2_negative)';
t_2_2_negative = E'*(R_2_negative)';
The problem is for the matrices t
which are derived from [t]×= ±E12R
, I should have a 3x1 matrix but the answers are 3x3 matrices.