Ask Your Question
0

Cannot retrieve matrix from an xml file using FileStorage

asked 2016-04-10 04:09:51 -0600

bob409 gravatar image

updated 2016-04-10 04:10:44 -0600

I am storing features in form of a matrix in an xml file using FileStorage

FileStorage f("trial.xml",FileStorage::WRITE);
Mat feature;
f<<"feature"<<feature;

By executing the above code, a trial.xml file is created

<?xml version="1.0"?>
<opencv_storage>
<features type_id="opencv-matrix">
  <rows>1</rows>
  <cols>8</cols>
  <dt>f</dt>
  <data>
   3.35365832e-001 1.21951215e-002 9.14634094e-002 6.30081296e-002
    3.31300795e-001 1.01626012e-002 9.95934904e-002 5.69105670e-002</data></features>
 </opencv_storage>

However, I cannot retrive the matrix from the xml file.

FileStorage fs("trial.xml",FileStorage::READ);
Mat data;
fs["data"]>>data;
cout<<data<<endl;

The Mat data is empty: []

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2016-04-10 04:17:27 -0600

LorenaGdL gravatar image

updated 2016-04-10 05:52:03 -0600

It should be fs["features"]>>data;. Have in mind than reading a matrix is not only reading the numbers inside, but also reading its dimensions (rows and cols), type, etc.

Refer to documentation for more details and examples:

http://docs.opencv.org/2.4/modules/co...

http://docs.opencv.org/master/tutoria...

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-04-10 04:09:51 -0600

Seen: 182 times

Last updated: Apr 10 '16