我必须重建一些可见特征的3D位置,这些特征在从汽车拍摄的两张图像上是可见的。这些照片有不同的位置和角度。我能够从第一张图像中导出矩阵K
,因为该项目的要求是该特定图像的相机校准矩阵
对于3D重建,我必须遵循以下步骤:
- 找到匹配点,并估计基本矩阵
F
- 由于我没有关于
P2
(第二图像的投影矩阵(的任何信息,所以我必须使用Essential矩阵才能检索第二相机的矩阵R
和T
- 执行三角测量并构建三维位置
%% 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)';
问题是,对于从[t]×= ±E12R
导出的矩阵t
,我应该有一个3x1矩阵,但答案是3x3矩阵。
在搜索后,我找到了矩阵t,我必须这样做:
t = reshape(U(:, 3) / max(abs(U(:, 3))), [3, 1]);
P2_1(:, :, 1) = cat(2, U*W*V', t);
P2_2(:, :, 2) = cat(2, U*W*V', -t);
P2_3(:, :, 3) = cat(2, U*W'*V', t);
P2_4(:, :, 4) = cat(2, U*W'*V', -t);