【问题标题】:Converting angular velocity to quaternion in OpenCV在 OpenCV 中将角速度转换为四元数
【发布时间】:2012-08-21 11:32:14
【问题描述】:

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

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

我的角速度是

Mat w;  //1x3

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

Mat qwt;   //1x4

我找不到这方面的信息,有什么想法吗?

【问题讨论】:

  • 四元数表示旋转或方向。角速度是它的导数。目前尚不清楚您要做什么。
  • 我猜他想将角速度表示为一个四元数来更新四元数值作为这个产品:q(k)=q(k-1)*qwt
  • 被 qwt 表示为四元数的角速度
  • 是的,就是这样!我想使用角速度更新每帧的四元数。
  • 好吧,那么如果你使用角速度,每一帧都要小心,因为 w 应该乘以帧之间的时间。

标签: opencv quaternions


【解决方案1】:

如果我理解正确,你想从这个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;
    }
}

【讨论】:

  • 可能是您在以下行中犯了错误吗? qwt.at&lt;float&gt;(0)=qwt.at&lt;float&gt;(0)=qwt.at&lt;float&gt;(0)=0.0f;你一遍又一遍地设置同一个组件。
【解决方案2】:

几乎所有关于四元数、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解释透彻。

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

【讨论】:

    【解决方案3】:

    一个小技巧可以摆脱那些 cos 和 sin 函数。四元数 q(t) 的时间导数为:

    dq(t)/dt = 0.5 * x(t) * q(t)

    其中,如果角速度为 {w0, w1, w2},则 x(t) 是 {0, w0, w1, w2} 的四元数。请参阅 David H Eberly 的书第 10.5 节以获取证据

    【讨论】:

    • 你的四元数是 {x,y,z,w} 还是 {w,x,y,z}?
    猜你喜欢
    • 2020-02-26
    • 2018-04-05
    • 2011-04-19
    • 2021-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-03
    相关资源
    最近更新 更多