title: convert an opencv affine matrix to CGAffineTransform
body: <p>I'd like to take an affine matrix that I have from OpenCV:</p>
  
  <pre><code>Mat T = getAffineTransform(src_pt, dst_pt);
  </code></pre>
  
  <p>and then convert it into a CGAffineTransform for use in Core Graphics/Objective-C/iOS. (<a href="https://developer.apple.com/library/mac/#documentation/graphicsimaging/reference/CGAffineTransform/Reference/reference.html" rel="nofollow">CGAffineTransform docs</a>)</p>
  
  <p>I've tried:</p>
  
  <pre><code>CGAffineTransform t = CGAffineTransformIdentity;
  t.a = T.at&lt;float&gt;(0,0);
  t.b = T.at&lt;float&gt;(0,1);
  t.c = T.at&lt;float&gt;(1,0);
  t.d = T.at&lt;float&gt;(1,1);
  t.tx = T.at&lt;float&gt;(0,2);
  t.ty = T.at&lt;float&gt;(1,2);
  </code></pre>
  
  <p>This works fine for x and y translations, but NOT if there is any rotation in the matrix. Something seems to be missing since the resulting image seems to be skewed strangely. I've tried multiplying <code>.b</code> and <code>.c</code> by -1 and switching <code>.b</code> and <code>.c</code>, but neither of those seemed to work. The image still appeared incorrectly skewed.</p>
  
  <p>Edit: I should mention that it's <em>almost</em> rotated correctly. When I switch b and c it's at least rotated in the right direction. It just seems a bit off, as in rotated a little too far.</p>