Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Retrieve matrix from an xml file using FileStorage

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: []

Retrieve Cannot retrieve matrix from an xml file using FileStorage

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: []