【问题标题】:Rotation and Translation order issue in openCV with SolvePnP使用 SolvePnP 在 openCV 中的旋转和平移顺序问题
【发布时间】:2014-11-22 23:28:51
【问题描述】:

我有一个 openGL 3D 渲染和一个正在看棋盘的相机。 3D 渲染在 3D 渲染的棋盘上显示一个小十字准线,由 3D 渲染的相机指向。当现实生活中的相机移动时,十字准线和 3D 相机应该移动相同。我的翻译工作完美。但是我的旋转总是围绕棋盘的原点旋转,而不是围绕它的当前位置。我知道这意味着矩阵乘法顺序是错误的。但我不知道它在哪里。据我所知,我遵循的程序应该有效。

这是我遵循的基本流程:

  • SolvePnP -> 获取 rvec 和 tvec
  • rodrigues -> rvec 到 RMatrix
  • 转置 RMatrix (-RMatrix * tvec) -> 得到 TVector
  • CVpose=

[RMatrix TVector(0) ... TVector(1) ... TVector(2) 0, 0, 0, 1 ]

  • transpose(CVpose) -> 获取 CVpose'
  • 将 CVpose' 逐个元素分配给 GLpose

本节我的实际代码:

solvePnP(Mat(boardPoints), Mat(imagePoints),intrinsics, distortion,rvec, tvec, false);
//calculate camera pose
Rodrigues(rvec, rotM); // rotM is camera rotation matrix
RTMat = rotM.t();

//create full transform matrix
for(int row = 0; row < 3; row++){
    for(int col = 0; col < 3; col++){
        CVpose.at<double>(row,col) = RTMat.at<double>(row,col);
    }
    CVpose.at<double>(row, 3) = (tvec.at<double>(row, 0));
}
CVpose.at<double>(3, 3) = 1.0f;

// invert axes for openGL
cvToGl.at<double>(0, 0) = 1.0f; // Invert the x axis
cvToGl.at<double>(1, 1) = -1.0f; // Invert the y axis
cvToGl.at<double>(2, 2) = 1.0f; // invert the z axis
cvToGl.at<double>(3, 3) = 1.0f;

CVpose =  cvToGl * CVpose;

//assign CVpose to GLpose with col major and row major notation taken into account
for(int row = 0; row < 4; row++){
    for(int col = 0; col < 4; col++){
        GLpose[col][row] = GLpose.at<double>(row,col);
    }
}

//rotate camera to face chessboard in GL
GLpose= glm::rotate(GLpose, 180.0f, vec3(1.0f, 0.0f, 0.0f))  ;`

我错过了什么吗?如果需要,我会提供更多信息。

【问题讨论】:

    标签: c++ opencv opengl rotation rotational-matrices


    【解决方案1】:

    我通过以下过程解决了这个问题:

    1. SolvePnP() -> 得到 rvec 和 tvec
    2. rodrigues() -> rvec 到 RMatrix
    3. 转置 RMatrix -> RTMatrix
    4. (-RTMatrix * tvec) -> 获取TVector
    5. 创建一个 4x4 的 openGL 身份矩阵 ->(我称之为 GLtransform)
    6. GLtransform = glm::translate() -> 由 TVector 翻译
    7. GLtransform = glm::rotate() -> 由 rvec 旋转
    8. GLtransform = glm::rotate() -> 旋转以修复 CV 和 GL 轴之间的兼容性
    9. 绘制 GL 变换

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-14
      • 2017-05-15
      • 1970-01-01
      • 2011-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多