Read and write Mat to xml file under root node
Hello,
I am trying to save Mat to a xml file. I follow this tutorial and its works very well : link
The problem I have a xml with some value before and if I tried to write in this file, It will erase all my data to remplace with a root node <opencv_storage>. For example if tried to write in a xml like this :
<?xml version="1.0"?>
<hello>
<world>hello world</world>
</hello>
If I tried to write in this file the program will with a error :
OpenCV Error: Parsing error (test.xml(2): <opencv_storage> tag is missing) in icvXMLParse, file ..\..\..\..\opencv\modules\core\src\persistence.cpp, line 2281
I can resolve this problem creating an empty node <\opencv_storage> in the xml file, like this :
<?xml version="1.0"?>
<hello>
<world>hello world</world>
<opencv_storage></opencv_storage>
And then close the root node (don't why if I put the </hello> in the xml file it will be after <opencv_storage>).
But I still have problems to read the mat, because I think FileStorage is waiting a root node <opencv_storage>, so I was wondering is somebody have an idea to resolve this problem.
Best regards
haven't tried, but it's probably meant this way(the opencv tag has to go all around it):
<?xml version="1.0"?>
<opencv_storage>
<hello>
<world>hello world</world>
</hello>
</opencv_storage>
see it's just a quite primitive key-value store. also you can't have 2 <hello> keys at the same level ( they've got to be unique)
Yeah I just tested and It works great, It just that I wanted a different name for the root node and read a mat from a node lower than the root node for examle :
<?xml version="1.0"?> <hello> <world> <opencv_storage> Here my data from the mat <opencv_storage> </world> </hello>
But I think I have a idea about how to do this on a inderect way. Thanks for your answer
to my experience, it does not like "nested" things too much.
if you want it the easy way, stick to a single list of key-value pairs
and the opencv_storage must be the most outer tag.
you can still use different files.