首页 文章

如何测试基本矩阵?

提问于
浏览
1

在我的应用程序中,我使用2个摄像头进行3D对象重建 . 为了校准相机,我使用2组图像计算基本矩阵,以便找到相机姿势(旋转和平移) . 我使用SVD找到R和T.但是当我试图检查矩阵的准确性时,它根本不起作用:重建点的位置与实际位置不同 .

如何检查我是否以正确的方式?

这是我使用的Matlab代码:

D2=[-0.168164529475, 0.110811875773, -0.000204013531649, -9.05039442317e-05, 0.0737585102411];
D1=[-0.187817541965, 0.351429195367, -0.000521080240718, -0.00052088823018, -1.00569541826];
K2=[2178.5537139, 0.0, 657.445233702;0.0, 2178.40086319, 494.319735021;0.0, 0.0, 1.0];
K1=[2203.30000377, 0.0, 679.24264123;0.0, 2202.99249047, 506.265831986;0.0, 0.0, 1.0];

load pts1.dat;   % load image points from CAM42
load pts2.dat;   % load image points from CAM49

% calcul de la matrice fondamentale
disp('Finding stereo camera matrices ...');
disp('(By default RANSAC optimasation method is used.)');
disp('- 4 : LTS');
disp('- 3 : MSAC');
disp('- 2 : RANSAC');
disp('- 1 : Norm8Point');
disp('- 0 : LMedS');


c = input('Chose method to find F :', 's');
if nargin > 0
    switch c
        case 4
            method = 'LTS';
        case 3
            method = 'MSAC';
        case 2
            method = 'RANSAC';
        case 1
            method = 'Norm8Point';
        otherwise
            method = 'LMedS';
    end
else
    method = 'RANSAC';
end
%F = estimateFundamentalMatrix(points2', points1', 'Method', method, 'NumTrials', 4000, 'DistanceThreshold', 1e-4)


% calcul de la matrice essentielle
E = K2' * F * K1;

% calcul de R et T à partir de la décomposition SVD
[U S V] = svd(E);

Z = [0  -1  0; 
     1  0  0; 
     0  0  0]; % matrice anti-symetrique

W = [0 -1  0;
     1  0  0;
     0  0  1];   % matrice orthogonale

fprintf(sprintf('\ndev(Vt) = %f', det(V')));
fprintf(sprintf('\ndet(U) = %f', det(U )));


Ra = U * W * V'
Rb = U * W'* V'
T  = U * Z * U';
T0 = U(: , 3)
T = [T(2,1); -T(3, 1); T(3, 2)];

disp('=======================');
% R1 = [Ra  T0]
% R2 = [Ra -T0]
% R3 = [Rb  T0]
% R4 = [Rb -T0]


% test des matrices trouvées. ---------------------------------------------
pti = 10;    % point index
x1 = points1(pti,:)';
disp('x1 (real):'); x1 = [x1;1]
x2 = points2(pti,:)';
disp('x2 (real):'); x2 = [x2;1]
disp('===========');
x2 = Ra*x1 + T0      % [Ra, T0]
x2 = Ra*x1 - T0      % [Ra, -T0]
x2 = Rb*x1 + T      % [Rb, T0]
x2 = Rb*x1 - T      % [Rb, -T0]
fprintf('\nx1t*F*x2 = %f\n',x2'*F*x1);
disp('Epipolar line');
l1 = F*x1
l2 = F*x2

谢谢 .

1 回答

相关问题