title: opencv giving camera pose - rvec and tvec - with mismatched coordinate system
body: <p>I need to find the pose (rotation matrix + translation vector) for a camera, and for that I am using <code>cv2.solvePnP()</code>, but the results I get from photos don't match.</p>
  
  <p>In order to debug, I created (with numpy) a "debugging 3d scene" composed of some object points (four corners of a square), some camera points (focal point, principal point and four corners of the virtual projection plane) and parameters (focal distance, initial orientation).</p>
  
  <p>Then, I construct a general rotation matrix by multiplying three axis rotation matrices, apply this general rotation to the camera (<code>numpy.dot()</code>), project the object points in the virtual projection plane (line-plane intersection algorithm), and calculate the in-plane 2D coordinates (point-line distance) to the projection plane axes.</p>
  
  <p>After doing this (objectpoints to imagepoints via rotationmatrix), I feed the imagepoints and the objectpoints to <code>cv2.Rodrigues(cv2.solvePnP(...))</code> and get a matrix "not quite identical" to the one I used, only because of transposition and some elements with opposite signal (negative vs. positive), respecting this relation:</p>
  
  <pre><code>solvepnp_rotmatrix = my_original_matrix.transpose * [ 1  1  1] 
                                                      [ 1  1 -1] 
                                                      [-1 -1  1] 
  </code></pre>
  
  <p>Although the rotation matrix mismatch is "solveable" with this hack, the TRANSLATION VECTOR gives coordinates that don't make sense to me.</p>
  
  <p>I suspect there are mismatches between my 3D model (handedness, axes orientation, order of rotations) and the model used by opencv:</p>
  
  <ul>
  <li>I use OpenGL-like coordinate system (X increases to the right, Y increases upwards, and Z increases toward the observer;</li>
  <li>I applied the rotations in the order that made more sense to me (all right-handed, first around global Z, then around global X, then around global Y);</li>
  <li>The image plane is between object and camera focal point (virtual projection plane, instead of real/CCD);</li>
  <li>The origin of my image plane (virtual CCD) is lower-left corner (Xpix increases to the right, Ypx increases upwards.</li>
  </ul>
  
  <p>My questions are:</p>
  
  <p>Given that the terms of the rotation matrix are identical, only transposed and with different signal in some terms, is it possible that I am confusing some of <code>openCV</code> conventions (handedness, order of rotations, axis direction)? And how can I discover which one(s)?</p>
  
  <p>Also, is there a way to relate my handmade translation vector to the tvec returned by <code>solvePnP</code>? (of course, ideally, the best would be to make the coordinate systems to match, in the first place).</p>
  
  <p>Any help will be most welcome!</p>