title: Image rotation angle calculation in OpenCV
body: <p>I would like to calculate the rotation angle for the hand object. The purpose for this step is to make the object aligned. Its main axis and secondary axis are parallel to the x and y axis in the coordinate system. </p>
  
  <p>First, I use MATLAB to do this.
  1. find white pixels coordinates in the hand object, return a n by 2 matrix.
  2. calculate covariance matrix for this n by 2 matrix.
  3. use eigs function to get the eigenvalues and eigenvectors,eigenvecotor matrix is a 2 by 2 matrix.
  4. the rotation angle is calculated by sigma=arctan(eigenvecotor(1,1)/eigenvecotor(2,1))*180/pi</p>
  
  <p>The result is good.</p>
  
  <p>How could I do it as the same in OpenCV? I have tested it for many times, but the result is not correct.</p>
  
  <p>I also tried with the following code, but using this method is also not correct.</p>
  
  <p>(result is the Mat for hand image)</p>
  
  <pre><code>   Moments mu =  moments(result, false);                          
     Point2d mc(mu.m10/mu.m00, mu.m01/mu.m00);                       
     double m11 = mu.m11 ;
     double m20 = mu.m20 ;
     double m02 = mu.m02 ;
     double orientation = 0.5*atan(2*m11 / (m20 - m02))*180/M_PI; 
  </code></pre>
  
  <p>Could someone help me for the code or give me some clues that how can I implement the same method as in Matlab in OpenCV?</p>
  
  <p>Thank you so much for your attention and time.</p>