本文介绍了OpenCV imread()在iOS上不返回任何图像数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用OpenCV的 imread()
函数在 cv :: Mat $ c $中加载JPEG图像c>,但它在iOS上失败(相同的代码适用于OS X)。返回的矩阵已分配且有效,但为空(即它不包含任何数据)。
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).
执行函数 imread()
和 imwrite()
在iOS下工作?
Do the functions imread()
and imwrite()
work under iOS?
推荐答案
它有效,至少当你在正在运行的应用程序的Documents-Directory中保存和加载时。
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);
这篇关于OpenCV imread()在iOS上不返回任何图像数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!