N.J*_*N.J 21 c++ opencv euler-angles computer-vision
我正在使用单个对象的两个图像,该对象从其第一个图像开始特定程度.
我已经计算了每个图像的POSE,并使用Rodergues()将旋转矢量转换为Matrix.现在我如何计算并查看它从第一个位置旋转了多少?
我尝试了很多方法,但答案并非接近
编辑:我的相机是固定的只有物体在移动.
Kri*_*ish 38
我们可以使用以下公式从旋转矩阵获得欧拉角.
给定3×3旋转矩阵

3个欧拉角是



这里atan2是相同的反正切函数,通过象限检查,您通常可以在C或Matlab中找到.
注意:如果y轴周围的角度恰好为+/- 90°,则必须小心.在这种情况下,第一列和最后一行中的所有元素(除了下角中的一个,即1或-1)将为0(cos(1)= 0).一种解决方案是将围绕x轴的旋转固定在180°并且计算围绕z轴的角度:atan2(r_12,-r_22).
另请参阅https://www.geometrictools.com/Documentation/EulerAngles.pdf,其中包括六个不同欧拉角度顺序的实现.
Bet*_*eta 11
如果R是(3x3)旋转矩阵,那么旋转角度将是acos((tr(R)-1)/ 2),其中tr(R)是矩阵的轨迹(即对角元素的总和) ).
这就是你要求的; 我估计有90%的可能性不是你想要的.
我想在这里做出贡献,因为我正在解决同样的问题。我通过发布一个纯 python 实现来将 3-D 旋转矩阵 (3x3) 转换为相应的滚动 (Rx) 、俯仰 (Ry) 、偏航 (Rz) 角度,从而为上述答案增加价值。
参考伪代码: https://www.gregslabaugh.net/publications/euler.pdf(链接在某种程度上不再有效/在 2021 年被破坏......但为了完整性,我将其包含在此处)
参考问题设置:假设我们有一个 3x3 旋转矩阵,我们想要提取以度为单位的欧拉角。我将使 Python 实现尽可能“明显”,以便于理解脚本中发生的事情。各个编码人员可以对其进行优化以供自己使用。
假设:我们首先绕 x 轴旋转,然后是 y 轴,最后是 z 轴。当您调整此代码片段时,必须遵守此顺序定义。
"""
Illustration of the rotation matrix / sometimes called 'orientation' matrix
R = [
R11 , R12 , R13,
R21 , R22 , R23,
R31 , R32 , R33
]
REMARKS:
1. this implementation is meant to make the mathematics easy to be deciphered
from the script, not so much on 'optimized' code.
You can then optimize it to your own style.
2. I have utilized naval rigid body terminology here whereby;
2.1 roll -> rotation about x-axis
2.2 pitch -> rotation about the y-axis
2.3 yaw -> rotation about the z-axis (this is pointing 'upwards')
"""
from math import (
asin, pi, atan2, cos
)
if R31 != 1 and R31 != -1:
pitch_1 = -1*asin(R31)
pitch_2 = pi - pitch_1
roll_1 = atan2( R32 / cos(pitch_1) , R33 /cos(pitch_1) )
roll_2 = atan2( R32 / cos(pitch_2) , R33 /cos(pitch_2) )
yaw_1 = atan2( R21 / cos(pitch_1) , R11 / cos(pitch_1) )
yaw_2 = atan2( R21 / cos(pitch_2) , R11 / cos(pitch_2) )
# IMPORTANT NOTE here, there is more than one solution but we choose the first for this case for simplicity !
# You can insert your own domain logic here on how to handle both solutions appropriately (see the reference publication link for more info).
pitch = pitch_1
roll = roll_1
yaw = yaw_1
else:
yaw = 0 # anything (we default this to zero)
if R31 == -1:
pitch = pi/2
roll = yaw + atan2(R12,R13)
else:
pitch = -pi/2
roll = -1*yaw + atan2(-1*R12,-1*R13)
# convert from radians to degrees
roll = roll*180/pi
pitch = pitch*180/pi
yaw = yaw*180/pi
rxyz_deg = [roll , pitch , yaw]
Run Code Online (Sandbox Code Playgroud)
希望这对其他编码人员有所帮助!