Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to read a Matrix from a child node with FileStorage API

Hello guys,

I am having a little issue here. I saved a couple of mat as child nodes in xml using the Filestorage API in opencv. However when i try to read them back the filestorage API reads the same values which are wrong for all the Matrices in the xml file. I don't know where am getting it wrong. please help.

Here is my code for writing and reading.

FileStorage file(filename, FileStorage::WRITE);
file << "Features" << "{";
for (int i = 0; i < TrainFeatureVector.size(); i++){
  string element1 = "f" + to_string(i);
  file << element1 << TrainFeatureVector[i];
}
file << "}"

FileStorage fs(filename, FileStorage::READ);
Mat feat;
string element;
string element1;
FileNode k = fs["Features"];
for (int i = 0; i < k.size(); i++){
 element1 = "f" + to_string(i);
 k[element1] >> feat;
 Fvector.push_back(feat);}

Here is my xml file C:\fakepath\sxml.png

How to read a Matrix from a child node with FileStorage API

Hello guys,

I am having a little issue here. I saved a couple of mat as child nodes in xml using the Filestorage API in opencv. However when i try to read them back the filestorage API reads the same values which are wrong for all the Matrices in the xml file. I don't know where am getting it wrong. please help.

Here is my code for writing and reading.

FileStorage file(filename, FileStorage::WRITE);
file << "Features" << "{";
for (int i = 0; i < TrainFeatureVector.size(); i++){
  string element1 = "f" + to_string(i);
  file << element1 << TrainFeatureVector[i];
}
file << "}"

FileStorage fs(filename, FileStorage::READ);
Mat feat;
string element;
string element1;
FileNode k = fs["Features"];
for (int i = 0; i < k.size(); i++){
 element1 = "f" + to_string(i);
 k[element1] >> feat;
 Fvector.push_back(feat);}

Here is my xml file C:\fakepath\sxml.png