Reputation: 1018
There are a ton of questions about converting a UIIMage to a cv::Mat with CV_8UC4 encoding. There's even the tutorial on the OpenCV iOS site.
However, for the life of me I can't figure out how to convert a UIImage to 8UC3 correctly. Using the stock OpenCV example, trying to convert to 8UC1 also breaks, as the cv:Mat has a ton of null pointers after initialization.
Any insight into how I might be able to do this correctly? Thanks!
Upvotes: 0
Views: 2447
Reputation: 499
Try calling the following after converting UIImage to cv::Mat...
cvtColor(srcMat, destMat, CV_RGBA2BGR);
Upvotes: 2
Reputation: 791
For me when I want to convert from UIImage into Mat simply I use the predefined function UIImageToMat like this:
UIImageToMat(extractedUIImage, matImage);
But first you need to include this header file from openCV:
#import <opencv2/highgui/ios.h>
Same to convert from Mat into UIImage:
UIImage *extractedImage = MatToUIImage(matImage);
Just give it a try it works fine for me
Upvotes: 2