【发布时间】: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