Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting angular velocity to quaternion in OpenCV

I need the angular velocity expressed as a quaternion for updating the quaternion every frame with the following expression in OpenCV:

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

My angular velocity is

Mat w;  //1x3

I would like to obtain a quaternion form of the angles

Mat qwt;   //1x4

I couldn't find information about this, any ideas?

like image 319
Mar de Romos Avatar asked Aug 21 '12 11:08

Mar de Romos


Video Answer


2 Answers

If I understand properly you want to pass from this Axis Angle form to a quaternion.

As shown in the link, first you need to calculate the module of the angular velocity (multiplied by delta(t) between frames), and then apply the formulas.

A sample function for this would be

// 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;
    }
}
like image 159
Jav_Rock Avatar answered Oct 16 '22 12:10

Jav_Rock


Almost every transformation regarding quaternions, 3D space, etc is gathered at this website.

You will find time derivatives for quaternions also.

I find it useful the explanation of the physical meaning of a quaternion, which can be seen as an axis angle where

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

Then the conversion uses:

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

Here is explained thoroughly.

Hope this helped to make it clearer.

like image 39
Carlos Cachalote Avatar answered Oct 16 '22 13:10

Carlos Cachalote