title: Resolving rotation matrices to obtain the angles
body: <p>I have used this <a href="http://docs.opencv.org/doc/tutorials/features2d/feature_homography/feature_homography.html" rel="nofollow">code</a> as a basis to detect my rectangular target in a scene.I use ORB and Flann Matcher.I have been able to draw the bounding box of the detected target in my scene successfully using the findHomography() and perspectiveTransform() functions. 
  <br>
  The reference image (img_object in the above code) is a straight view of only the rectangular target.Now the target in my scene image may be tilted forwards or backwards.I want to find out the angle by which it has been tilted.I have read various posts and came to the conclusion that the homography returned by findHomography() can be decomposed to the rotation matrix and translation vector. I have used code from https:/gist.github.com/inspirit/740979 recommended by <a href="http://urbanar.blogspot.in/2011/04/from-homography-to-opengl-modelview.html" rel="nofollow">this link</a> translated to C++.This is the Zhang SVD decomposition code got from the camera calibration module of OpenCV.I got the complete explanation of this decomposition code from O'Reilly's Learning OpenCV book.
  <br>
  I also used solvePnP() on the the keypoints returned by the matcher to  cross check the rotation matrix and the translation vector returned from the homography decomposition but they do not seem to the same.
  <br>
  I have already the measurements of the tilts of all my scene images.i found 2 ways to retrieve the angles from the rotation matrix to check how well they match my values.</p>
  
  <ul>
  <li><p>Given a 3×3 rotation matrix</p>
  
  <p>R = <br>[ r_{11} &amp; r_{12} &amp; r_{13} ]<br>
        [ r_{21} &amp; r_{22} &amp; r_{23} ]<br>
        [ r_{31} &amp; r_{32} &amp; r_{33} ]<br></p>
  
  <p>The 3 Euler angles are</p>
  
  <p>theta_{x} = atan2(r_{32}, r_{33})</p>
  
  <p>theta_{y} = atan2(-r_{31}, sqrt{r_{32}^2 + r_{33}^2})</p>
  
  <p>theta_{z} = atan2(r_{21}, r_{11})</p></li>
  </ul>
  
  <p><br></p>
  
  <ul>
  <li>The axis,angle representation - Being R a general rotation matrix, its corresponding rotation axis u
  and rotation angle θ can be retrieved from:<br>
  cos(θ) = ( trace(R) − 1) / 2<br>
  [u]× = (R − R⊤) / 2 sin(θ)</li>
  </ul>
  
  <p><br>
  I calculated the angles using both the methods for the rotation matrices obtained from the homography decomposition and the solvepnp().All the angles are different and give very unexpected values.
  <br>
  Is there a hole in my understanding?I do not understand where my calculations are wrong.Are there any alternatives i can use?</p>