title: Camera position in world coordinate from cv::solvePnP
body: <p>I have a calibrated camera (intrinsic matrix and distortion coefficients) and I want to know the camera position knowing some 3d points and their corresponding points in the image (2d points).</p>
  
  <p>I know that <code>cv::solvePnP</code> could help me, and after reading <a href="https://stackoverflow.com/questions/14444433/calculate-camera-world-position-with-opencv-python">this</a> and <a href="https://stackoverflow.com/questions/14515200/python-opencv-solvepnp-yields-wrong-translation-vector?lq=1">this</a> I understand that I the outputs of solvePnP <code>rvec</code> and <code>tvec</code> are the rotation and translation of the object in camera coordinate system.</p>
  
  <p>So I need to find out the camera rotation/translation in the world coordinate system.</p>
  
  <p>From the links above it seems that the code is straightforward, in python:</p>
  
  <pre><code>found,rvec,tvec = cv2.solvePnP(object_3d_points, object_2d_points, camera_matrix, dist_coefs)
  rotM = cv2.Rodrigues(rvec)[0]
  cameraPosition = -np.matrix(rotM).T * np.matrix(tvec)
  </code></pre>
  
  <p>I don't know python/numpy stuffs (I'm using C++) but this does not make a lot of sense to me:</p>
  
  <ul>
  <li>rvec, tvec output from solvePnP are 3x1 matrix, 3 element vectors</li>
  <li>cv2.Rodrigues(rvec) is a 3x3 matrix</li>
  <li>cv2.Rodrigues(rvec)[0] is a 3x1 matrix, 3 element vectors</li>
  <li>cameraPosition is a 3x1 * 1x3 matrix multiplication that is a.. 3x3 matrix. how can I use this in opengl with simple <code>glTranslatef</code> and <code>glRotate</code> calls?</li>
  </ul>