I'd like to take an affine matrix that I have from OpenCV:
Mat T = getAffineTransform(src_pt, dst_pt);
and then convert it into a CGAffineTransform for use in Core Graphics/Objective-C/iOS. (CGAffineTransform docs)
I've tried:
CGAffineTransform t = CGAffineTransformIdentity;
t.a = T.at<float>(0,0);
t.b = T.at<float>(0,1);
t.c = T.at<float>(1,0);
t.d = T.at<float>(1,1);
t.tx = T.at<float>(0,2);
t.ty = T.at<float>(1,2);
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 .b
and .c
by -1 and switching .b
and .c
, but neither of those seemed to work. The image still appeared incorrectly skewed.
Edit: I should mention that it's almost 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.