aihot  2017-04-28 23:30:03  OpenCV |   查看评论   
// text - mapping  
  • fs << "{" << "One" << 1;  
  • fs << "Two" << 2 << "}"

  • 读取这些结构的时候,会用到FileNode和FileNodeIterator数据结构。对FileStorage类的[]操作符会返回FileNode数据类型,对于一连串的node,可以使用FileNodeIterator结构,例如:

    1. FileNode n = fs["strings"]; // Read string sequence - Get node  
    2. if (n.type() != FileNode::SEQ)  
    3. {  
    4. cerr << "strings is not a sequence! FAIL" << endl;  
    5. return 1;  
    6. }  
    7. FileNodeIterator it = n.begin(), it_end = n.end(); // Go through the node  
    8. for (; it != it_end; ++it)  
    9. cout << (string)*it << endl;  



    5. 读写自己的数据结构

    这部分比较复杂,参考最后的实例中的MyData结构自己领悟吧

    最后,我这里上一个实例,供大家参考。

    源文件里填入如下:

    1. #include <opencv2/core/core.hpp>  
    2. #include <iostream>  
    3. #include <string>  
    4.   
    5. using namespace cv;  
    6. using namespace std;  
    7.   
    8. void help(char** av)  
    9. {  
    10.     cout << endl   
    11.         << av[0] << 显示了OpenCV序列化功能的用法."         << endl  
    12.         << "用法: "                                                                      << endl  
    13.         <<  av[0] << " outputfile.yml.gz"                                                 << endl  
    14.         << "输出文件可以是XML(xml)或YAML(yml / yaml)。 你甚至可以压缩它 "  
    15.         << "
     

    除特别注明外,本站所有文章均为 赢咖4注册 原创,转载请注明出处来自OpenCV学习笔记(六)——对XML和YAML文件实现I/O操作

    留言与评论(共有 0 条评论)
       
    验证码:
    [lianlun]1[/lianlun]