Reading HAAR feature information from XML model
I am busy trying to build a visualisation of the by the cascalde classifier framework trained models. Up to now the FileStorage, FileNode and FileNodeIterator have helped me in grabbing every single value from the model except from the weight of each feature rectangle.
The form of a feature:
<_>
<rects>
<_>23 10 1 3 -1.</_>
<_>23 11 1 1 3.</_>
</rects>
<tilted>0</tilted></_>
<_>
Grabbing the information of each subrectangle can be done by the current code. The it_features is the iterator that runs over all features, the code handling that does just as expected and is therefore neglected.
...
vector< vector<int> > current_feature_dimensions;
FileNode rectangles = (*it_features)["rects"];
FileNodeIterator it_rect = rectangles.begin(), it_rect_end = rectangles.end();
vector<int> values;
for(int idr = 0; it_rect != it_rect_end; it_rect++, idr++ ){
(*it_rect) >> values;
current_feature_dimensions.push_back(values);
}
....
If I then visualise (only partially showed because the output is too large) this all using a loop over the vector values than the last value of the score is always 0.
for(int i = 0; i < feature_data.size(); i ++){
cerr << "Feature " << i << " - #rectangles = " << feature_data[i].size() << ": ";
for (int j = 0; j < feature_data[i].size(); j++){
vector<int> rect = feature_data[i][j];
cerr << "[" << rect[0] << " " << rect[1] << " " << rect[2] << " " << rect[3] << " " << rect[5] << "] ";
}
cerr << endl;
}
Feature 1059 - #rectangles = 2: [2 4 15 13 0] [7 4 5 13 0]
Feature 1060 - #rectangles = 2: [16 2 3 10 0] [17 2 1 10 0]
Feature 1061 - #rectangles = 2: [6 10 2 1 0] [7 10 1 1 0]
Feature 1062 - #rectangles = 2: [1 1 18 16 0] [10 1 9 16 0]
Feature 1063 - #rectangles = 2: [14 4 3 15 0] [15 4 1 15 0]
Feature 1064 - #rectangles = 2: [19 13 1 2 0] [19 14 1 1 0]
Feature 1065 - #rectangles = 2: [2 6 5 8 0] [2 10 5 4 0]
I tried the following things: changing the vector type to double and float with both reading and grabbing them from the XML file but also when writing them out with the cerr function. However this did not work. The float approach also generates a zero for the last value. The double case generates the must unrealistic values ever.
Feature 1061 - #rectangles = 2: [6 10 2 1 2.42092e-322] [7 10 1 1 2.42092e-322]
Feature 1062 - #rectangles = 2: [1 1 18 16 2.42092e-322] [10 1 9 16 2.42092e-322]
Feature 1063 - #rectangles = 2: [14 4 3 15 2.42092e-322] [15 4 1 15 2.42092e-322]
Feature 1064 - #rectangles = 2: [19 13 1 2 2.42092e-322] [19 14 1 1 2.42092e-322]
Feature 1065 - #rectangles = 2: [2 6 5 8 2.42092e-322] [2 10 5 4 2.42092e-322]
Any insights would be welcome! My debugging has lead me to believe that it is due to the fact that the FileNode interface cannot handle different types in between a single tag ... and thus this cannot be solved. On the other hand, the code base suggests that the weights is stored as ...
maybe shovelling all the values from the rects node into the same container is a bad idea.
this looks like you're better off treating each single value as a FileNode on its own
(but again, no idea, really, have not tried)
I have studied the source code, but afaik you can only use FileNode until the level of the last xml or yml tags. That is exactly what I do. But then I have the problem of a single tag containing both integer and double values. I should be able to get in touch with the person that programmed this interface, to ask why the hell they used doubles there, if not a single double values is ever stored there.
But I will try your suggestion right now and report back!
or , at least read the FileNodeIterator only up to end()-1, and put the last value into a float