Reputation: 29
In my application, I use 2 cameras for 3D object reconstruction. To calibrate the cameras, I compute the fundamental matrix using 2 sets of images in order to find the camera pose (rotation and translation). I use SVD to find the R and T. But when I try to check the accuracy of my matrices, it doesn't work at all: the position of the reconstructed points doesn't feat with the real positions.
How can I check if I am in the right way?
Here is my Matlab code that i use :
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
Thank you.
Upvotes: 1
Views: 5219
Reputation: 2132
your fundamental matrix has to satisfy the correspondence condition
x' * F * x = 0
for point correspondences x'
and x
. (see http://www.robots.ox.ac.uk/~vgg/hzbook/hzbook2/HZepipolar.pdf, pp 257-260)
you may have a look at the question camera-motion-from-corresponding-images, which probably help you to check if you are on the right way.
Upvotes: 6