I'm using OpenCV's camera calibration function, I have 34 images of the checkerboard on a turntable, taken from a static camera. The camera position from the initial tvec is approximately correct, however the rvec is totally wrong. I ploted the orientation in matlab to indicate the problem.
The formula I used should be correct like,this.
My question is why these orientations are wrong ? is this normal for the calibration algorithm? Matlab uses Z as the up axis, could this be my visualization code problem ?
Thanks.
Update:
I put my plot code here, I suspect it has the problem.
function drawCameraPoses(rvec, tvec)
if (size(tvec,2) ~= 3 || size(tvec,1) <= 0)
disp('tvec must contain 3 columns and greater than 0 row') ;
exit ;
end
if (size(rvec) ~= size(tvec))
disp('rvec must be at the same size of the tvec.') ;
end
%plot camera positions
figure ;
%watch out xyz order
plot3(tvec(:,1), tvec(:,3), tvec(:,2),'r+') ;
hold on ;
grid on ;
plotrange = [max(tvec);min(tvec)] ;
disp(plotrange)
xyrange = [max([plotrange(1,1),plotrange(1,3)]) ; min([plotrange(2,1),plotrange(2,3)])];
disp(xyrange)
plotscaleFactor = 1.5 ;
xlim([xyrange(2) - abs(xyrange(2))*(plotscaleFactor - 1.0), xyrange(1) + abs(xyrange(1))*(plotscaleFactor - 1.0)]) ;
ylim([xyrange(2) - abs(xyrange(2))*(plotscaleFactor - 1.0), xyrange(1) + abs(xyrange(1))*(plotscaleFactor - 1.0)]) ;
zlim([plotrange(2,2) - abs(plotrange(2,2)) * (plotscaleFactor - 1.0), plotrange(1,2) + abs(plotrange(1,2)) * (plotscaleFactor - 1.0)]) ;
%plot camera orientation
for i = 1 : size(rvec,1)
[x,y,z] = getEndPoint(tvec(i,:),rvec(i,:)) ;
line([tvec(i,1), x],[tvec(i,3),z],[tvec(i,2),y],'Color','r');
end
end
function [x,y,z] = getEndPoint(t,r)
length = 50 ;
unitR = r / norm(r) ;
unitR = unitR * length ;
x = t(1) + unitR(1) ;
y = t(2) + unitR(2) ;
z = t(3) + unitR(3) ;
end