aihot  2017-04-28 23:30:03  OpenCV |   查看评论   
在其扩展名中指定这一点,如xml.gz yaml.gz等... "                  << endl  
  •         << "使用FileStorage,您可以使用<<and>>运算符来序列化OpenCV中的对象" << endl  
  •         << "例如: - 创建一个类并将其序列化"                         << endl  
  •         << "             - 用它来读写矩阵."                            << endl;  
  • }  
  •   
  • class MyData  
  • {  
  • public:  
  •     MyData() : A(0), X(0), id()  
  •     {}  
  •     explicit MyData(int) : A(97), X(CV_PI), id("mydata1234"// 明确地避免隐式转换
  •     {}  
  •     void write(FileStorage& fs) const                        // 为此类编写序列化
  •     {  
  •         fs << "{" << "A" << A << "X" << X << "id" << id << "}";  
  •     }  
  •     void read(const FileNode& node)                          // 读这个类的序列化
  •     {  
  •         A = (int)node["A"];  
  •         X = (double)node["X"];  
  •         id = (string)node["id"];  
  •     }  
  • public:   // 数据成员
  •     int A;  
  •     double X;  
  •     string id;  
  • };  
  •   
  • // 必须为FileStorage中的序列化定义这些写入和读取功能才能正常工作
  • void write(FileStorage& fs, 
  •  

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

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