相机外部矩阵到世界坐标

时间:2017-02-09 09:58:12

标签: c++ matrix

我有一个相机矩阵,如下:

 0.999995,-0.00313698,4.29446e-06, 0.632334
 0.00313675,0.999936,0.0108695,0.0111429
 -3.83917e-05,-0.0108695,0.999941,-21.8834
0,0,0,1

由旋转矩阵R组成:

 0.999995,-0.00313698,4.29446e-06,
 0.00313675,0.999936,0.0108695,
 -3.83917e-05,-0.0108695,0.999941

和翻译矩阵T:

  0.632334, 0.0111429,-21.8834

我需要做的是将它从相机转移到世界空间。我有这个公式,是:

    'Rotation from camera to world is simply 
inv(R) = transpose(R). 
T is the pre-rotated camera center, 
T = -R C, so C = -inv(R) T = (x,y,z).'

我是矩阵数学的初学者,我对如何继续感到困惑。我如何使用我的R矩阵,在c ++中,执行上述操作?

谢谢。

1 个答案:

答案 0 :(得分:0)

感谢来自@Scheff的正确方向的推动,我有一个答案:

void cameraMatrixToWorldSpace()
{

    Eigen::Matrix3f R0;
    Eigen::Vector3f T0;
    Eigen::Vector3f C0;

    T0 << 0.632334, 0.0111429, -21.8834;

    R0 << 0.999995, -0.00313698, 4.29446e-06,
        0.00313675, 0.999936, 0.0108695,
        -3.83917e-05, -0.0108695, 0.999941;


//inverse rotation matrix
    R0.transposeInPlace();  

    std::cout << "rotation 0: " << R0 <<  std::endl;

    //to euler radians
    Vector3f ea0 = R0.eulerAngles(0, 1, 2);

    cout << "Euler 0 :" << endl;
    cout << ea0 << endl << endl;

    //world space translation
    C0 = -R0 * T0;

    std::cout << " Translation 0 : " << C0 << std::endl;

}