Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

UIImage to cv::Mat and back to UIImage rotating 90 degrees

I have the following code running in iOS:

UIImage *image = ((ImageViewController *)[self.childViewControllers lastObject]).image;

cv::Mat mat;

UIImageToMat(image, mat);
if (mat.elemSize() > 1)
    cvtColor(mat, mat, CV_BGR2GRAY);

self.image = MatToUIImage(mat);

((ImageViewController *)[self.childViewControllers lastObject]).image = self.image;

My problem is that after running this code, my image is rotated 90 degrees. But only SOME images. (well, only 1 image that I have found so far). MOST images display as expected. I can't figure out why this image is rotating, and it is driving me crazy. I can't risk other images doing this unexpectedly, so I need to figure out what is going on...