Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

There are two ways:

1) Read images using iOS functions and convert UIImage to cv::Mat later.

NSString* filePath = [[NSBundle mainBundle]
                          pathForResource:@"demo" ofType:@"png"];
UIImage* resImage = [UIImage imageWithContentsOfFile:filePath];
cv::Mat cvImage;
UIImageToMat(resImage, cvImage);

2) Use imdecode() function

//create file handle
NSFileHandle* handle = [NSFileHandle fileHandleForReadingAtPath:fileName];
//read contents of the file
NSData *data = [handle readDataToEndOfFile];
//read image from the data buffer
cv::Mat cvImage = cv::imdecode(cv::Mat(1, [data length], CV_8UC1, (void*)data.bytes), CV_LOAD_IMAGE_UNCHANGED);