Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Ah, I dug up that part of the other project, and I told you something, several things, wrong. OpenGL always puts the camera at (0,0,0). So you have to reverse the coordinates. I'm putting this as an answer so I can put in a bunch of code.

To go from OpenGL to OpenCV, this is what I do. Note that there's a stop in the Viz module along the way. So there's some redundancies.

Mat ident;
ident.create(3, 3, pose.type());
setIdentity(ident, -1);
ident.at<float>(0, 0) = 1;
pose(Rect(0, 0, 3, 3)) = (ident * pose(Rect(0, 0, 3, 3)).t()).t();
Mat R = pose(Rect(0,0,3,3));
Mat tBuffer = pose(Rect(3, 0, 1, 3));
R = R.t();
tBuffer = (-R * tBuffer);
Rodrigues(R, rBuffer);

Therefore, this should be what you do.

Mat ident;
ident.create(3, 3, pose.type());
setIdentity(ident, -1);
ident.at<float>(0, 0) = 1;
Mat R;
Rodrigues(rvec, R);
R = R.t();
Mat tvecTemp = (-R * tvec);
R = (ident * R).t()).t();

Then you put R and tvecTemp into your 4x4 view matrix. I'm sorry I don't have very much experience with OpenGL or I'd try it myself to verify it works.