CvFileStorage. How to save our custom structures with OpenCV functions
In this tutorial we go to show how to save our custom structures with opencv functions.
We go to imagine we have this structure in our program.
Opencv can save data in two formats: XML or YAML. This formats are markup languages.
For write or read a file, we go to use cvOpenFileStorage function, the functions returns a CvFileStorage structure pointer. This pointer we use to read or write values into.
We can open a file in two ways: for read or write. The function to open file is cvOpenFileStorage
One time we have our CvFileStorage initialized then we can save our data. To save the data we need create Nodes. XML and YAML are markup languages, and they are defined with nodes.
First we go to create one node that contains all structure data. And inside of this node we need create one node for each variable.
For create a node we need open and close this node, as we do with xml, then we use cvStartWriteStruct and cvEndWriteStruct.
Between the start and end node we go to insert each new node with asigned variable. The variable we must save as some of this types: int, raw (array), real or string with this functions:
cvWriteInt cvWriteRawData cvWriteReal cvWriteString Then for save our structure we go to create this code: