Read and write Mat to xml file under root node

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

Leena gravatar image

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


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"?>
<world>hello world</world>

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"?>
<world>hello world</world>

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


haven't tried, but it's probably meant this way(the opencv tag has to go all around it):

<?xml version="1.0"?>



<world>hello world</world>



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 -0500 )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 -0500 )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 -0500 )edit