我有一个作业,必须使用透视变换来计算和绘制一些点,但是我不确定我的结果是正确的,因为使用相机坐标的3d图看起来与使用图像坐标的2d图非常不同。你能帮我了解怎么了吗?
给出的结果是:相机位于,以世界坐标(以米为单位)指定。相机坐标系通过绕世界参考的Y轴旋转,因此其旋转矩阵为 θ = 160 ö 瓦特- [R c ^ = [ c ^ Õ 小号(θ )0 š 我Ñ (θ )0 1 0 - š 我Ñ (θ )0 Ç Ô 小号(θ ) ]
相机参数为:,,,s x = s y = 0.01 m m / p x o xö Ŷ = 240 p X
采样点(在世界坐标中):
我必须计算并绘制相机坐标系和图像坐标系中的点,因此我在Octave中编写了以下代码:
%camera intrinsic parameters
f = 16
Sx = 0.01
Sy = 0.01
Ox = 320
Oy = 240
%given points, in world coordinate
wP1 = transpose([1, 1, 0.5])
wP2 = transpose([1, 1.5, 0.5])
wP3 = transpose([1.5, 1.5, 0.5])
wP4 = transpose([1.5, 1, 0.5])
% camera translation matrix
wTc = transpose([-1, 1, 5])
% rotation angle converted to rad
theta = 160 / 180 * pi
%camera rotation matrix
wRc = transpose([cos(theta), 0, sin(theta); 0, 1, 0; -sin(theta), 0, cos(theta)])
%transform the points to homogeneous coordinates
wP1h = [wP1; 1]
wP2h = [wP2; 1]
wP3h = [wP3; 1]
wP4h = [wP4; 1]
%separate each line of the rotation matrix
R1 = transpose(wRc(1 , :))
R2 = transpose(wRc(2 , :))
R3 = transpose(wRc(3 , :))
%generate the extrinsic parameters matrix
Mext = [wRc, [-transpose(R1) * wTc; -transpose(R2) * wTc; -transpose(R3) * wTc]]
%intrinsic parameters matrix
Mint = [-f/Sx, 0, Ox; 0, -f/Sy, Oy; 0, 0, 1]
% calculate coordinates in camera coordinates
cP1 = wRc * (wP1 - wTc)
cP2 = wRc * (wP2 - wTc)
cP3 = wRc * (wP3 - wTc)
cP4 = wRc * (wP4 - wTc)
% put coordinates in a list for plotting
x = [cP1(1), cP2(1), cP3(1), cP4(1), cP1(1)]
y = [cP1(2), cP2(2), cP3(2), cP4(2), cP1(2)]
z = [cP1(3), cP2(3), cP3(3), cP4(3), cP1(3)]
%plot the points in 3D using camera coordinates
plot3(x, y, z, "o-r")
pause()
% calculate the points in image coordinates
iP1 = Mint * (Mext * wP1h)
iP2 = Mint * (Mext * wP2h)
iP3 = Mint * (Mext * wP3h)
iP4 = Mint * (Mext * wP4h)
%generate a list of points for plotting
x = [iP1(1) / iP1(3), iP2(1) / iP2(3), iP3(1) / iP3(3), iP4(1) / iP4(3), iP1(1) / iP1(3)]
y = [iP1(2) / iP1(3), iP2(2) / iP2(3), iP3(2) / iP3(3), iP4(2) / iP4(3), iP1(2) / iP1(3)]
plot(x, y, "o-r")
pause()
这些是我从脚本中获得的图:我期望它们有些相似,但看起来并不相似。
绘制相机坐标
绘制图像坐标