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

asked 2014-01-21 22:13:54 -0600

Jim gravatar image

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...

edit retag flag offensive close merge delete


I have that same problem. I am new to OpenCV so its probably a simple mistake. Does anyone know the answer?

Tony Davis gravatar imageTony Davis ( 2014-01-28 05:42:24 -0600 )edit
Tony Davis gravatar imageTony Davis ( 2014-02-21 10:11:42 -0600 )edit