使用侧倾-俯仰-偏航角变换图像(图像校正)

托莫德·豪金(Tormod Haugene)

我正在开发需要校正从移动相机平台拍摄的图像的应用程序。该平台可测量横滚,俯仰和偏航角,我想通过此信息的某种转换使其看起来像是直接从上方拍摄的图像。

换句话说,我希望将一个平整的正方形平放在地面上,并从远处以某种相机方向拍摄,然后进行变换,以使正方形在之后变得完全对称。

我一直在尝试通过OpenCV(C ++)和Matlab进行此操作,但是我似乎缺少有关如何完成此操作的一些基本信息。

在Matlab中,我尝试了以下方法:

%% Transform perspective
img = imread('my_favourite_image.jpg');
R = R_z(yaw_angle)*R_y(pitch_angle)*R_x(roll_angle);
tform = projective2d(R);   
outputImage = imwarp(img,tform);
figure(1), imshow(outputImage);

其中R_z / y / x是标准旋转矩阵(以度为单位)。

对于某些偏航旋转,一切都很好:

R = R_z(10)*R_y(0)*R_x(0);

结果如下:

图像绕Z图像轴旋转10度

如果我尝试围绕X轴或Y轴旋转相同的图像量,则会得到如下结果:

R = R_z(10)*R_y(0)*R_x(10);

图像绕X图像轴旋转10度

但是,如果我旋转10度,除以某个大数字,它看起来就可以了。但话又说回来,这是迄今为止没有任何研究价值的结果:

R = R_z(10)*R_y(0)*R_x(10/1000);

图像绕X图像轴旋转10/1000度

有人可以帮我理解为什么绕X轴或Y轴旋转会使转换变得疯狂吗?有什么办法可以解决这个问题,而不用除以随机数和其他魔术技巧吗?这是否可以使用某种Euler参数来解决?任何帮助将不胜感激!

更新:完整的设置和测量

For completeness, the full test code and initial image has been added, as well as the platforms Euler angles:

Code:

%% Transform perspective
function [] = main()
    img = imread('some_image.jpg');
    R = R_z(0)*R_y(0)*R_x(10);
    tform = projective2d(R);   
    outputImage = imwarp(img,tform);
    figure(1), imshow(outputImage);
end

%% Matrix for Yaw-rotation about the Z-axis
function [R] = R_z(psi)
    R = [cosd(psi) -sind(psi) 0;
         sind(psi)  cosd(psi) 0;
         0          0         1];
end

%% Matrix for Pitch-rotation about the Y-axis
function [R] = R_y(theta)
    R = [cosd(theta)    0   sind(theta);
         0              1   0          ;
         -sind(theta)   0   cosd(theta)     ];
end

%% Matrix for Roll-rotation about the X-axis
function [R] = R_x(phi)
    R = [1  0           0;
         0  cosd(phi)   -sind(phi);
         0  sind(phi)   cosd(phi)];
end

The initial image:

在此处输入图片说明

Camera platform measurements in the BODY coordinate frame:

Roll:     -10
Pitch:    -30
Yaw:      166 (angular deviation from north)

From what I understand the Yaw-angle is not directly relevant to the transformation. I might, however, be wrong about this.

Additional info:

I would like specify that the environment in which the setup will be used contains no lines (oceanic photo) that can reliably used as a reference (the horizon will usually not be in the picture). Also the square in the initial image is merely used as a measure to see if the transformation is correct, and will not be there in a real scenario.

Tormod Haugene

So, this is what I ended up doing: I figured that unless you are actually dealing with 3D images, rectifying the perspective of a photo is a 2D operation. With this in mind, I replaced the z-axis values of the transformation matrix with zeros and ones, and applied a 2D Affine transformation to the image.

Rotation of the initial image (see initial post) with measured Roll = -10 and Pitch = -30 was done in the following manner:

R_rotation = R_y(-60)*R_x(10); 
R_2d       = [   R_rot(1,1)  R_rot(1,2) 0; 
                 R_rot(2,1)  R_rot(2,2) 0;
                 0           0          1    ] 

This implies a rotation of the camera platform to a virtual camera orientation where the camera is placed above the scene, pointing straight downwards. Note the values used for roll and pitch in the matrix above.

Additionally, if rotating the image so that is aligned with the platform heading, a rotation about the z-axis might be added, giving:

R_rotation = R_y(-60)*R_x(10)*R_z(some_heading); 
R_2d       = [   R_rot(1,1)  R_rot(1,2) 0; 
                 R_rot(2,1)  R_rot(2,2) 0;
                 0           0          1    ] 

Note that this does not change the actual image - it only rotates it.

结果,围绕Y轴和X轴旋转的初始图像如下所示:

在此处输入图片说明

如上所示,执行此转换的完整代码为:

% Load image
img = imread('initial_image.jpg'); 

% Full rotation matrix. Z-axis included, but not used.
R_rot = R_y(-60)*R_x(10)*R_z(0); 

% Strip the values related to the Z-axis from R_rot
R_2d  = [   R_rot(1,1)  R_rot(1,2) 0; 
            R_rot(2,1)  R_rot(2,2) 0;
            0           0          1    ]; 

% Generate transformation matrix, and warp (matlab syntax)
tform = affine2d(R_2d);
outputImage = imwarp(img,tform);

% Display image
figure(1), imshow(outputImage);



%*** Rotation Matrix Functions ***%

%% Matrix for Yaw-rotation about the Z-axis
function [R] = R_z(psi)
    R = [cosd(psi) -sind(psi) 0;
         sind(psi)  cosd(psi) 0;
         0          0         1];
end

%% Matrix for Pitch-rotation about the Y-axis
function [R] = R_y(theta)
    R = [cosd(theta)    0   sind(theta);
         0              1   0          ;
         -sind(theta)   0   cosd(theta)     ];
end

%% Matrix for Roll-rotation about the X-axis
function [R] = R_x(phi)
    R = [1  0           0;
         0  cosd(phi)   -sind(phi);
         0  sind(phi)   cosd(phi)];
end

感谢您的支持,希望对您有所帮助!

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

相机俯仰/偏航到方向向量

Android:从方位角,侧倾和俯仰获取设备方向

偏航,俯仰滚动至glm :: rotate

使用Eigen库从旋转矩阵获得俯仰和偏航

迅捷陀螺仪偏航,俯仰,滚动

使用LiipImagineBundle转换图像

Unity Google VR-从Android设备获取旋转,偏航和俯仰值

Pannellum 360图像查看器-获得俯仰和偏航

OpenGL中鼠标输入背后的数学运算和偏航/俯仰值

为什么PlayerController“拥有”偏航俯仰和摇摆,而角色“拥有”其位置?

如何在Swift中获取iPhone的当前俯仰,偏航和侧倾?

旋转矢量传感器值到方位角,侧倾和俯仰

在Flutter中获取设备方向(偏航,横摇和俯仰)

Unity3d根据俯仰,横滚和偏航角度列表平滑地旋转对象

我如何才能绝对获得ARAnchor的偏航,俯仰和滚动?

视觉框架提供不精确的侧倾和偏航值

如何计算3D点的偏航角,俯仰角和侧倾角?

如何从前向矢量计算俯仰和偏航值

如何根据偏航,俯仰和横滚值旋转对象

使用Cwiid Python的Wiimote Motion Plus的俯仰和偏航

从ARKit中的faceAnchor中提取偏航/俯仰/滚动

使用OpenCV扭曲/校正图像

为什么我不能使用Matlab获得正确的傅立叶变换图像?

处理:从matrix4x4获取偏航角,俯仰和横滚角

俯仰和偏航-位置和传送

JavaFX 8转换为俯仰,偏航和侧倾旋转角度

使用Python转换图像

2 个传感器读数融合(偏航、俯仰)

如何使用箭头键旋转/变换图像