gpt4 book ai didi

c++ - 在 OpenCV 中读取嵌套的 XML

转载 作者:行者123 更新时间:2023-11-28 07:00:33 25 4
gpt4 key购买 nike

这个 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;

最佳答案

您可以使用:

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了解更多信息。

关于c++ - 在 OpenCV 中读取嵌套的 XML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22559875/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com