在OpenCV中将角速度转换为四元数

问题描述 投票:7回答:3

我需要用四元数表示的角速度,以在OpenCV中用以下表达式更新每帧四元数:

q(k)=q(k-1)*qwt;

我的角速度是

Mat w;  //1x3

我想获得角度的四元数形式

Mat qwt;   //1x4

我找不到有关此的信息,有什么想法吗?

opencv quaternions
3个回答
6
投票

如果我理解正确,您想通过此Axis Angle form to a quaternion

如链接中所示,首先需要计算角速度的模块(乘以帧之间的delta(t)),然后应用公式。

一个示例函数将是

// w is equal to angular_velocity*time_between_frames
void quatFromAngularVelocity(Mat& qwt,const Mat&w)
{
    const float x = w.at<float>(0);
    const float y = w.at<float>(1);
    const float z = w.at<float>(2);
    const float angle = sqrt(x*x + y*y + z*z);  // module of angular velocity

    if (angle > 0.0) // the formulas from the link
    {
        qwt.at<float>(0) = x*sin(angle/2.0f)/angle;
        qwt.at<float>(1) = y*sin(angle/2.0f)/angle;
        qwt.at<float>(2) = z*sin(angle/2.0f)/angle;
        qwt.at<float>(3) = cos(angle/2.0f);
    } else    // to avoid illegal expressions
    {
        qwt.at<float>(0) = qwt.at<float>(0)=qwt.at<float>(0)=0.0f;
        qwt.at<float>(3) = 1.0f;
    }
}

4
投票

几乎所有有关四元数,3D空间等的变换都收集在此website

您还将找到四元数的时间导数。

我发现对四元数的物理意义的解释很有用,可以将其视为轴角,>

a = angle of rotation
x,y,z = axis of rotation.

然后转换使用:

q = cos(a/2) + i ( x * sin(a/2)) + j (y * sin(a/2)) + k ( z * sin(a/2))

Here进行了详细说明。

希望这有助于使其更加清晰。


1
投票

与此相关的一个小技巧,就是摆脱那些cos和sin函数。四元数q(t)的时间导数为:

© www.soinside.com 2019 - 2024. All rights reserved.