4

I've been trying to warp a couple of photos with exact Quaternions for weeks without luck. The equation below doesn't seem to rotate the camera position as well as I'd expect from exact positions. Am I doing it right? Is there something I'm missing?

I understand that simply passing a Quaternion is not enough to stitch a photo, but it should be enough to align the photos?

Here's the formula:

double divmult = 2.0 / lsq;
double xx = divmult * x * x;
double yy = divmult * y * y;
double zz = divmult * z * z;

double wx = divmult * w * x;
double wy = divmult * w * y;
double wz = divmult * w * z;
double xy = divmult * x * y;
double xz = divmult * x * z;
double yz = divmult * y * z;

cameras_global[imageCounter].R = (Mat_<float>(3, 3) << ( 1 - yy - zz ),    -( xy - wz ),   -( xz + wy ),
                                  ( xy + wz ),        -( 1 -xx -zz ), -( yz - wx ),
                                  ( xz - wy ),        -( yz + wx ),   -( 1 -xx -yy )   );
0

1 Answer 1

2

OpenCV does not directly support quaternions. Rather than fixing your calculations, I would go with a simpler conversion. The closest thing it has is axis-angle vectors to represent 3D rotations (also named Rodrigues angles). I would convert to axis-angle, then multiply the axis by the angle to obtain Rodrigues angles. After that, you can use OpenCV's built-in functions, for instance cv::Rodrigues to convert to a 3x3 rotation matrix.

Sign up to request clarification or add additional context in comments.

5 Comments

Correct me if I'm wrong but the link you've referenced seems to be doing the opposite of what you're saying. It seems to be converting angular velocity to a quaternion?
Perfect, thanks! One last question, (sorry in advance if its a noob question), but - after I convert the quaternion -> rodrigues angles, do I use the return from rodrigues to camera_global[0].R? Or what do I do with the angles?
Rodrigues(v, camera_global[0].R)
please check my latest question here: stackoverflow.com/questions/38861985/… , you can see the results there from simply passing the equation above. Is that considered "good"? Or will I get more accurate results from converting to Rodrigues?
It supports since 2020. See opencv4/opencv2/core/quaternion.hpp