Ask Your Question

Revision history [back]

Hello,

I faced a similar situation and here is how I found the camera position and rotations :

After solvePnP, we get the rotation and the translation for the object - we need to do the inverse to get the camera position and rotation.

CvInvoke.Rodrigues(rotationVector, rotationMatrix);        
// transpose the rotation to get the camera rotation 
rotationMatrix = rotationMatrix.Transpose();
Matrix4x4 R = new Matrix4x4();

copy the rotation matrix to R, and swap the 2nd and 3rd row to swap y and z. After that, rotate the matrix by 90 degrees. This will give you the rotation matrix for the camera. Convert the rotation matrix to a quaternion. and set that to the camera rotation.

As for position,

camera.transform.position = negativematrix * R * Tvec;

where negativematrix is a matrix with 1 on the diagonals.