; // text - mapping
fs << "{" << "One" << 1;
fs << "Two" << 2 << "}";
读取这些结构的时候,会用到FileNode和FileNodeIterator数据结构。对FileStorage类的[]操作符会返回FileNode数据类型,对于一连串的node,可以使用FileNodeIterator结构,例如:
- FileNode n = fs["strings"]; // Read string sequence - Get node
- if (n.type() != FileNode::SEQ)
- {
- cerr << "strings is not a sequence! FAIL" << endl;
- return 1;
- }
- FileNodeIterator it = n.begin(), it_end = n.end(); // Go through the node
- for (; it != it_end; ++it)
- cout << (string)*it << endl;
5. 读写自己的数据结构
这部分比较复杂,参考最后的实例中的MyData结构自己领悟吧
最后,我这里上一个实例,供大家参考。
源文件里填入如下:
- #include <opencv2/core/core.hpp>
- #include <iostream>
- #include <string>
- using namespace cv;
- using namespace std;
- void help(char** av)
- {
- cout << endl
- << av[0] << " 显示了OpenCV序列化功能的用法." << endl
- << "用法: " << endl
- << av[0] << " outputfile.yml.gz" << endl
- << "输出文件可以是XML(xml)或YAML(yml / yaml)。 你甚至可以压缩它 "
- << "