I'm currently saving a large map of histogram data to xml for use in a later part of my program. I've noticed that it is cutting off the first value when loading and instead adding an empty value at the end.
A basic example is:
Correct Model:
<model1>0,1,1,1,1,1,1,0</model1>
Incorrect Loaded Model:
<model1>1,1,1,1,1,1,0,1.4013e-45</model1>
The layout of my xml file below where i is a changing value: <serial></serial> <classes> <class_i> <name></name> <m_i type_id="opencv-matrix"> </m_i> </class_i> </classes>
My import function is below:
int getClassHist(map<string, vector<Mat> >& savedClassHist){
int serial;
// Load in Class Histograms(Models)
FileStorage fs3("models.xml", FileStorage::READ);
fs3["Serial"] >> serial;
cout << "This is the serial: " << serial << endl;
FileNode fn = fs3["classes"];
if(fn.type() == FileNode::MAP){
// Create iterator to go through all the classes
for(FileNodeIterator it = fn.begin();it != fn.end();it++){
string clsNme = (string)(*it)["Name"];
savedClassHist[clsNme];
// Create node of current Class
FileNode clss = (*it)["Models"];
// Iterate through each model inside class, saving to map
for(FileNodeIterator it1 = clss.begin();it1 != clss.end();it1++){
FileNode k = *it1;
Mat tmp;
k >> tmp;
savedClassHist[clsNme].push_back(tmp);
}
}
fs3.release();
}else{
ERR("Class file was not map.");
exit(-1);
}
return serial;
}
It seems like an iterator problem so would be likely be in the it1 loop which is skipping the first value but i'm not sure why.??