【问题标题】:Using OpenCV FileStorage on iOS在 iOS 上使用 OpenCV FileStorage
【发布时间】:2012-03-28 18:16:51
【问题描述】:

我正在使用 OpenCV 创建一个对象分类器,为了避免每次启动应用程序时都必须训练分类器,我想以某种方式将它们存储在一个文件中。最方便的方法似乎是使用OpenCVs FileStorage class

我试了一下,但似乎没有用。尽管我没有收到错误,但保存的文件没有出现在任何地方。我想iOS不只是让你保存任何文件。另一种方法是将 YAML 作为字符串检索,将其转换为 NSString 并将其保存在属性列表中,但我不确定如何做到这一点,甚至是否可能。

任何帮助将不胜感激。

【问题讨论】:

    标签: c++ objective-c ios opencv objective-c++


    【解决方案1】:

    我设法让 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, NSUserDomainMask, YES);
    NSString *docs = [paths objectAtIndex:0];
    NSString *vocabPath = [docs stringByAppendingPathComponent:@"vocabulary.xml"];
    FileStorage fs([vocabPath UTF8String], FileStorage::READ);
    // vocab is a CvMat object representing the vocabulary in my bag of features model
    fs["vocabulary"] >> vocab;
    fs.release();
    

    【讨论】:

      猜你喜欢
      • 2014-07-03
      • 2012-06-23
      • 1970-01-01
      • 2013-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-12
      • 2015-09-24
      相关资源
      最近更新 更多