I have a sequence of camera poses and want to compute the angular change (pitch, yaw, roll) from the previous camera pose to the current one. As input I have 3x3 rotation matrices.
When I run the following code, it works 90% of the time, but in some cases -- like in the example below -- the Euler angles look funky despite very small changes in the quaternion: They jump from near 0 to values near PI, which might be still correct, but I cannot compute my relevant angles since I did not spontaneously flip the camera by PI. Is there any better way?
Code (looping, skipped first iteration)
std::cout << "----------\n";
std::cout << "R:\n" << R << std::endl;
Eigen::Quaternionf newQ(R);
Eigen::Quaternionf deltaQ = previousQ.conjugate()*newQ;
previousQ = newQ;
std::cout << "deltaQ:\nw = " << deltaQ.w() << "\nx = " << deltaQ.x() << "\ny = " << deltaQ.y() << "\nz = " << deltaQ.z() << std::endl;
std::cout << "Euler:\n" << deltaQ.toRotationMatrix().eulerAngles(0, 1, 2) << std::endl;
Console log
...
----------
R:
0.977515 -0.0134678 0.210437
0.0123623 0.999902 0.00656816
-0.210505 -0.00381899 0.977585
deltaQ:
w = 0.999747
x = 0.000164772
y = 0.022509
z = -0.000187157
Euler:
0.000338229
0.0450218
-0.000382023
----------
R:
0.966075 -0.0153634 0.257802
0.0136485 0.999871 0.0084406
-0.257899 -0.00463564 0.966161
deltaQ:
w = 0.999702
x = -0.000619047
y = 0.0243718
z = 0.000825906
Euler:
3.14031
3.09285
-3.13991
----------
...