MonsieurDart MonsieurDart - 1 year ago 274
iOS Question

OpenCV imread() returns no image data on iOS

I'm trying to use the OpenCV's

function to load a JPEG image in a
, 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
work under iOS?

Answer Source

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