我正在使用 OpenCV 的相机校准功能,我在转盘上有 34 张棋盘图像,这些图像是从静态相机拍摄的。初始 tvec 的相机位置大致正确,但 rvec 完全错误。我在 matlab 中绘制方向以指示问题。
我使用的公式应该是正确的,例如 this .
我的问题是为什么这些方向是错误的?这对于校准算法来说是否正常? Matlab 使用 Z 作为上轴,这会不会是我的可视化代码问题?
谢谢。
更新:
我把我的情节代码放在这里,我怀疑它有问题。
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
最佳答案
其实输出的rvec和tvec应该组成变换矩阵而不是简单的坐标赋值。灵感来自 calibration toolbox .
显示相机姿势的代码是,
function drawCameraPoses(rvec, tvec, flag)
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
if ~flag
%raw rvec tvec
for i = 1:size(tvec,1)
rotM = rodrigues(rvec(i,:)) ;
tvec(i,:) = -rotM'* tvec(i,:)' ;
rvec(i,:) = rodrigues(rotM') ;
end
end
%plot camera positions
figure ;
%watch out xyz order
plot3(tvec(:,1), tvec(:,2), tvec(:,3),'r+') ;
hold on ;
grid on ;
xlim([-1 1]) ;
ylim([-1 1]) ;
zlim([-1 1]) ;
%plot camera orientation
baseSymbol = 0.2 * [0 1 0 0 0 0;0 0 0 1 0 0;0 0 0 0 0 1] ;
for i = 1 : size(rvec,1)
%rotM already transposed
rotM = rodrigues(rvec(i,:)) ;
baseK = rotM * baseSymbol + tvec(i,:)' * ones(1,6) ;
plot3(baseK(1,:),baseK(2,:), baseK(3,:),'-b') ;
end
end
关于matlab - 使用 OpenCV 的相机校准结果使用 matlab 显示相机方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29558737/