簡體   English   中英

使用SolvePnP在openCV中旋轉和翻譯訂單問題

[英]Rotation and Translation order issue in openCV with SolvePnP

我有一個openGL 3D渲染和一個看着棋盤的照相機。 3D渲染在3D渲染的棋board上顯示一個小十字,由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))  ;`

我錯過了什么嗎? 如果需要,我會提供更多信息。

我通過以下步驟解決了這個問題:

  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. 繪制GLtransform

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM