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)) ;`
我错过了什么?如果需要,我会提供更多信息。