Reputation: 650
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;
Upvotes: 0
Views: 1657
Reputation: 50677
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.
Upvotes: 1