简体   繁体   中英

Reading nested XML in OpenCV

This stackoverflow question answers how to write data into an XML file with nesting: Creating an XML file in OpenCV

With Reference to the same question (and the accepted answer), how would I read the same file using the FileStorage class?

In short, how do I read the data the following code snippet writes?

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;

You can use:

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"];

Check out here for more info.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM