Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

maybe it gets easier, if you just write/read a vector/list of Mat's, and don't try to make it a 'dictionary'. your f1,f2,f3 keys are quite artificial here.

vector<Mat> TrainFeatureVector(4,Mat::eye(4,4,CV_32F)); // just for demo purpose
FileStorage fsw("ma.xml", FileStorage::WRITE);
fsw << "Features" << "[";
for (int i = 0; i < TrainFeatureVector.size(); i++)
{
    fsw << TrainFeatureVector[i];
}
fsw << "]";
fsw.release();


vector<Mat> TrainFeatureVector2;
FileStorage fsr("ma.xml", FileStorage::READ);
FileNode k = fsr["Features"];
for (FileNodeIterator it=k.begin(); it!=k.end(); ++it)
{
    Mat feature;
    (*it) >> feature;
    TrainFeatureVector2.push_back(feature);
}
cerr << TrainFeatureVector2[2];

[1, 0, 0, 0;
 0, 1, 0, 0;
 0, 0, 1, 0;
 0, 0, 0, 1]

 <?xml version="1.0"?>
<opencv_storage>
<Features>
  <_ type_id="opencv-matrix">
    <rows>4</rows>
    <cols>4</cols>
    <dt>f</dt>
    <data>
      1. 0. 0. 0. 0. 1. 0. 0. 0. 0. 1. 0. 0. 0. 0. 1.</data></_>
  <_ type_id="opencv-matrix">
    <rows>4</rows>
    <cols>4</cols>
    <dt>f</dt>
    <data>
      1. 0. 0. 0. 0. 1. 0. 0. 0. 0. 1. 0. 0. 0. 0. 1.</data></_>
  <_ type_id="opencv-matrix">
    <rows>4</rows>
    <cols>4</cols>
    <dt>f</dt>
    <data>
      1. 0. 0. 0. 0. 1. 0. 0. 0. 0. 1. 0. 0. 0. 0. 1.</data></_>
  <_ type_id="opencv-matrix">
    <rows>4</rows>
    <cols>4</cols>
    <dt>f</dt>
    <data>
      1. 0. 0. 0. 0. 1. 0. 0. 0. 0. 1. 0. 0. 0. 0. 1.</data></_></Features>
</opencv_storage>