Read and write Mat to xml file under root node

asked 2014-05-20 04:38:35 -0600

Leena gravatar image

updated 2014-05-20 04:56:51 -0600

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

edit retag flag offensive close merge delete

Comments

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)

berak gravatar imageberak ( 2014-05-20 05:18:05 -0600 )edit

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

Leena gravatar imageLeena ( 2014-05-20 05:34:42 -0600 )edit

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.

berak gravatar imageberak ( 2014-05-20 06:19:47 -0600 )edit