Erman
Erman

Reputation: 1603

OpenCV c++: How to write a list of string in xml file using OpenCV FileStorage?

I would like to create an xml file containing a list of string path of my images using Opencv's FileStorage, as you can see in the following:

<?xml version="1.0"?>
<opencv_storage>
  <imagelist>
    image1.png
    image2.png
    image3.png
    image4.png
    image5.png
    image6.png
  </imagelist>
</opencv_storage>

I found many solution to read this of file with FileNode, event on docs.opencv.org and I did not see how to create a such file.

Any help would be greatly appreciated.

Upvotes: 2

Views: 1360

Answers (1)

Leonardo Alves Machado
Leonardo Alves Machado

Reputation: 2837

From the link you posted, we have the following instructions:

Input/Output of vectors (arrays) and associative maps. As I mentioned beforehand, we can output maps and sequences (array, vector) too. Again we first print the name of the variable and then we have to specify if our output is either a sequence or map.

For sequence before the first element print the [ character and after the last one the ] character:

fs << "strings" << "[";     // text - string sequence
fs << "image1.jpg" << "Awesomeness" << "baboon.jpg";
fs << "]";   

For maps the drill is the same however now we use the { and } delimiter characters:

fs << "Mapping";   // text - mapping
fs << "{" << "One" << 1;
fs <<        "Two" << 2 << "}";

You might use these instructions as you wish (if you would like to make it in a single string, or maybe make a field out of each file...

Upvotes: 1

Related Questions