title: OpenCV: Essential Matrix Decomposition
body: <p>I am trying to extract Rotation matrix and Translation vector from the essential matrix. </p>
  
  <pre><code>&lt;pre&gt;&lt;code&gt;
  SVD svd(E,SVD::MODIFY_A);
  Mat svd_u = svd.u;
  Mat svd_vt = svd.vt;
  Mat svd_w = svd.w;
  
  Matx33d W(0,-1,0,
            1,0,0,
            0,0,1);
  
  Mat_&lt;double&gt; R = svd_u * Mat(W).t() * svd_vt; //or svd_u * Mat(W) * svd_vt; 
  Mat_&lt;double&gt; t = svd_u.col(2); //or -svd_u.col(2)
  &lt;/code&gt;&lt;/pre&gt;
  </code></pre>
  
  <p>However, when I am using R and T (e.g. to obtain rectified images), the result does not seem to be right(black images or some obviously wrong outputs), even so I used different combination of possible R and T. </p>
  
  <p>I suspected to E. According to the text books, my calculation is right if we have:</p>
  
  <blockquote>E = U*diag(1, 1, 0)*Vt</blockquote>
  
  <p>In my case svd.w which is supposed to be <em>diag(1, 1, 0)</em> [at least in term of a scale], is not so. Here is an example of my output:</p>
  
  <blockquote>svd.w =  [21.47903827647813; 20.28555196246256; 5.167099204708699e-010]</blockquote>
  
  <p>Also, two of the eigenvalues of E should be equal and the third one should be zero. In the same case the result is:</p>
  
  <blockquote>eigenvalues of E =  0.0000 + 0.0000i, 0.3143 +20.8610i, 0.3143 -20.8610i</blockquote>
  
  <p>As you see, two of them are complex conjugates.</p>
  
  <p>Now, the questions are:</p>
  
  <ul>
  <li>Is the decomposition of E and calculation of R and T done in a right way?</li>
  <li>If the calculation is right, why the internal rules of essential matrix are not satisfied by the results?</li>
  <li>If everything about E, R, and T is fine, why the rectified images obtained by them are not correct?</li>
  </ul>
  
  <p>I get E from fundamental matrix, which I suppose to be right. I draw epipolar lines on both the left and right images and they all pass through the related points (for all the 16 points used to calculate the fundamental matrix).</p>
  
  <p>Any help would be appreciated.
  Thanks!</p>