0
我有一個openGL 3D渲染器和一個看着棋盤的攝像機。 3D渲染在3D渲染棋盤上顯示一個小十字線,由3D渲染相機指向。當現實生活中的相機移動時,十字線和3D相機應該移動相同。我的翻譯完美地工作。但是我的旋轉總是圍繞棋盤的原點旋轉,而不是繞着它的當前位置旋轉。我知道這意味着有一個矩陣乘法的順序是錯誤的。但我不知道它在哪裏。據我所知,我遵循的程序應該工作。在openCV中使用SolvePnP旋轉和翻譯訂單問題
這是基本的過程中,我遵循:
- SolvePnP - >獲得RVEC和tvec
- 羅德里格 - > RVEC到RMatrix
- 轉RMatrix(-RMatrix * tvec) - >獲得TVector
- CVpose =
[RMatrix TVector(0) ... TVector(1) ... TVector(2) 0, 0, 0, 1 ]
- 轉(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)) ;`
我錯過了什麼?如果需要,我會提供更多信息。