c – 在iOS上使用OpenCV FileStorage

前端之家收集整理的这篇文章主要介绍了c – 在iOS上使用OpenCV FileStorage前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用OpenCV创建一个对象分类器,并且为了避免每次启动应用程序时都必须训练分类器,我想以某种方式将它们存储在一个文件中.最方便的方式似乎是使用 OpenCVs FileStorage class.

我给了它一个镜头,但它似乎没有工作.虽然我没有收到错误,但保存的文件没有出现在任何地方.我想iOS不只是让你保存任何文件.另一种方法是将YAML作为字符串检索,将其转换为NSString并将其保存在属性列表中,但我不确定如何做到这一点或者是否可行.

任何帮助将不胜感激.

解决方法

我设法让FileStorage类与iOS一起工作.问题是我需要确保文件是在iOS指定的文档目录中创建的.以下是一些示例代码
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *docs = [paths objectAtIndex:0];
NSString *vocabPath = [docs stringByAppendingPathComponent:@"vocabulary.xml"];
FileStorage fs([vocabPath UTF8String],FileStorage::WRITE);
// vocab is a CvMat object representing the vocabulary in my bag of features model
fs << "vocabulary" << vocab;
fs.release();

// READING

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,FileStorage::READ);
// vocab is a CvMat object representing the vocabulary in my bag of features model
fs["vocabulary"] >> vocab;
fs.release();
原文链接:https://www.f2er.com/c/114183.html

猜你在找的C&C++相关文章