Rodrigues into Eulerangles and vice versa

前端 未结 3 588
猫巷女王i
猫巷女王i 2020-12-07 17:22

I am useing solvePnP and i am getting a translation vector. Now i need to compare some euler angles with those results from solvePnP. And i want/need to transfer the euler

3条回答
  •  鱼传尺愫
    2020-12-07 17:55

    Adding a more concrete answer to supplement the other answers here. If you desire a direction vector instead of Euler angles, the process can indeed be simplified with a matrix multiplication, here's a quick solution:

    // The output is a direction vector in OpenGL coordinate system:
    // +X is Right on the screen, +Y is Up, +Z is INTO the screen
    static Vector3 ToDirectionVectorGL(const Mat& rodrigues1x3) noexcept
    {
        Mat rotation3x3;
        cv::Rodrigues(rodrigues1x3, rotation3x3);
    
        // direction OUT of the screen in CV coordinate system, because we care
        // about objects facing towards us - you can change this to anything
        // OpenCV coordsys: +X is Right on the screen, +Y is Down on the screen,
        //                  +Z is INTO the screen
        Vec3d axis{ 0, 0, -1 }; 
        Mat direction = rotation3x3 * Mat(axis, false);
    
        // normalize to a unit vector
        double dirX = direction.at(0);
        double dirY = direction.at(1);
        double dirZ = direction.at(2);
        double len = sqrt(dirX*dirX + dirY*dirY + dirZ*dirZ);
        dirX /= len;
        dirY /= len;
        dirZ /= len;
        // Convert from OpenCV to OpenGL 3D coordinate system
        return { float(dirX), float(-dirY), float(dirZ) };
    }
    

    If you are using this for head pose estimation, ensure the Rodrigues 1x3 rotation is formed properly around {0,0,0} or you might get odd results.

提交回复
热议问题