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...
I have that same problem. I am new to OpenCV so its probably a simple mistake. Does anyone know the answer?
http://stackoverflow.com/questions/14332687/converting-uiimage-to-cvmat provides the answer!
or even better https://gist.github.com/alex-cellcity/1531596