此stackoverflow问题解答了如何使用嵌套将数据写入XML文件: Creating an XML file in OpenCV
参考同一个问题(和接受的答案),我如何使用FileStorage类读取同一个文件?
简而言之,我如何阅读以下代码段写入的数据?
FileStorage fs; // Open it and check that it is opened;
fs << "SimpleData" << 1;
fs << "Structure" << "{";
fs << "firstField" << 1;
fs << "secondField" << 2;
fs << "}"; // End of structure node
fs << "SimpleData2" << 2;
答案 0 :(得分:1)
您可以使用:
FileStorage fs;
fs.open(filename, FileStorage::READ);
int SimpleData = (int) fs["SimpleData"];
FileNode n = fs["Structure"]; // Read Structure sequence - Get node
int firstField = (int)(n["firstField"]);
int secondField = (int)(n["secondField"]);
int SimpleData2 = (int) fs["SimpleData2"];
查看here了解详情。