MonsieurDart MonsieurDart - 4 months ago 123
iOS Question

OpenCV imread() returns no image data on iOS

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?

Answer

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);