I'm trying to use the OpenCV's imread()
function to load a JPEG image in a cv::Mat
, but it fails on iOS (the same code works on OS X). The returned matrix is allocated and valid, but empty (i.e. it contains no data).
Do the functions imread()
and imwrite()
work under iOS?
It works, at least when you're saving and loading to and from the Documents-Directory of your running app.
//Creating Path to Documents-Directory
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"ocv%03d.BMP", picNum]];
const char* cPath = [filePath cStringUsingEncoding:NSMacOSRomanStringEncoding];
const cv::string newPaths = (const cv::string)cPath;
//Save as Bitmap to Documents-Directory
cv::imwrite(newPaths, frame);
iOS defines its own file system and I do not believe that imread() and imwrite() interface with it. You need to use native functionality to load and save the images but once you get a pointer to the image data you can wrap it in a cv::Mat and then process it in opencv. It should not be difficult to write your own cv_imread(), cv_imwrite() functions for iOS.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With