假设我有一个物体相对于相机的坐标 X、Y、Z 和方向 Rx、Ry、Rz。
此外,我还有这个相机在世界上的坐标 U、V、W 和方向 Ru、Rv、Rw。
我如何将物体的位置(位置和旋转)转换为其在世界中的位置?
对我来说,这听起来像是基础变换,但我还没有找到清晰的来源。
我如何将物体的位置(位置和旋转)转换为其在世界中的位置?
对我来说,这听起来像是基础变换,但我还没有找到清晰的来源。
我找到了这篇文件,对这个主题非常清楚。 http://www.cse.psu.edu/~rcollins/CSE486/lecture12.pdf
其中包括反向操作,即从世界坐标系转换为相机3D坐标系。
Pc = R ( Pw - C ) 其中,Pc是相机世界中的一个点,Pw是正常世界中的一个点,R是旋转矩阵,C是相机平移。
不幸的是,添加LaTeX公式非常繁琐,所以我将提供一些matlab代码。
function lecture12_collins()
% for plotting simplicity I choose my points on plane z=0 in this example
% Point in the world
Pw = [2 2.5 0 1]';
% rotation
th = pi/3;
% translation
c = [1 2.5 0]';
% obtain world to camera coordinate matrix
T = GetT(th, c);
% calculate the camera coordinate
Pc = T*Pw
% get the camera to world coordinate
T_ = GetT_(th, c)
% Alternatively you could use the inverse matrix
% T_ = inv(R*C)
% calculate the worldcoordinate
Pw_ = T_*Pc
assert (all(eq(Pw_ ,Pw)))
function T = GetT(th, c)
% I have assumed rotation around the z axis only here.
R = [cos(th) -sin(th) 0 0
sin(th) cos(th) 0 0
0 0 1 0
0 0 0 1];
C = [1 0 0 -c(1)
0 1 0 -c(2)
0 0 1 -c(3)
0 0 0 1];
T = R*C;
function T_ = GetT_(th, c)
% negate the angle
R_ = [cos(-th) -sin(-th) 0 0
sin(-th) cos(-th) 0 0
0 0 1 0
0 0 0 1];
% negate the translation
C_ = [1 0 0 c(1)
0 1 0 c(2)
0 0 1 c(3)
0 0 0 1];
T_ = C_*R_
目前只涉及到位置问题。旋转方面,我已经通过额外的旋转知识解决了。我知道我的相机垂直于物体,并且它的旋转仅限于z轴。我可以将相机和物体的旋转相加。