Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Getting camera pos/rot after SolvePnP

Hi. Classical situation:

cv::Mat Rvec;
  cv::Mat_<float> Tvec;
  cv::Mat raux,taux;

  cv::solvePnP(points3d, points2d, calibration.getIntrinsic(), calibration.getDistorsion(),raux,taux);
  taux.convertTo(Tvec ,CV_32F);

  cv::Mat_<float> rotMat(3,3); 
  cv::Rodrigues(Rvec, rotMat);

  // Copy to transformation matrix
  for (int col=0; col<3; col++)
    for (int row=0; row<3; row++)
     pose3d.r().mat[row][col] = rotMat(row,col); // Copy rotation component
    pose3d.t().data[col] = Tvec(col); // Copy translation component

  pose3d = pose3d.getInverted();

And after it it's easy to draw something in OpenGL with setting MV matrix as pose3d (Matrix4x4). But, i getting crazy to find solution for getting camera position and rotation in world coordinate system to setup camera without setting MV matrix. This is required for drawing camera position in Unity editor application (e.g. here is the image, here is the photo camera and here is the player = scene render camera ). Thank you, folks. It's the biggest stuck for me as a programmer ever :(