Ask Your Question
0

Reading HAAR feature information from XML model

asked 2015-02-05 08:49:52 -0600

updated 2015-02-09 03:48:28 -0600

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 ... (more)

edit retag flag offensive close merge delete

Comments

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)

berak gravatar imageberak ( 2015-02-09 04:06:15 -0600 )edit

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.

StevenPuttemans gravatar imageStevenPuttemans ( 2015-02-09 04:11:41 -0600 )edit

But I will try your suggestion right now and report back!

StevenPuttemans gravatar imageStevenPuttemans ( 2015-02-09 04:13:06 -0600 )edit
1

or , at least read the FileNodeIterator only up to end()-1, and put the last value into a float

berak gravatar imageberak ( 2015-02-09 04:16:32 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2015-02-09 04:48:32 -0600

Thanks to @berak for pointing me to the correct solution. Didnt dig deep enough into that code! Solution to the problem below, giving the exact desired output.

// Grab the corresponding features dimensions and weights
FileNode features = cascade["features"];
vector< vector< rect_data > > feature_data;
FileNodeIterator it_features = features.begin(), it_features_end = features.end();
for(int idf = 0; it_features != it_features_end; it_features++, idf++ ){
    vector< rect_data > current_feature_rectangles;
    FileNode rectangles = (*it_features)["rects"];
    int nrects = (int)rectangles.size();
    for(int k = 0; k < nrects; k++){
        rect_data current_data;
        FileNode single_rect = rectangles[k];
        current_data.x = (int)single_rect[0];
        current_data.y = (int)single_rect[1];
        current_data.w = (int)single_rect[2];
        current_data.h = (int)single_rect[3];
        current_data.weight = (float)single_rect[4];
        current_feature_rectangles.push_back(current_data);
    }
    feature_data.push_back(current_feature_rectangles);
}

// DEBUG OUTPUT - feature rectangles
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++){
        rect_data data = feature_data[i][j];
        cerr << "[" << data.x << " " << data.y << " " << data.w << " " << data.h << " " << data.weight << "] ";
    }
    cerr << endl;
}

OUTPUT:

Feature 1056 - #rectangles = 2: [0 9 9 6 -1] [3 9 3 6 3] 
Feature 1057 - #rectangles = 2: [17 18 2 2 -1] [18 18 1 2 2] 
Feature 1058 - #rectangles = 2: [11 2 6 16 -1] [13 2 2 16 3] 
Feature 1059 - #rectangles = 2: [2 4 15 13 -1] [7 4 5 13 3] 
Feature 1060 - #rectangles = 2: [16 2 3 10 -1] [17 2 1 10 3] 
Feature 1061 - #rectangles = 2: [6 10 2 1 -1] [7 10 1 1 2] 
Feature 1062 - #rectangles = 2: [1 1 18 16 -1] [10 1 9 16 2] 
Feature 1063 - #rectangles = 2: [14 4 3 15 -1] [15 4 1 15 3] 
Feature 1064 - #rectangles = 2: [19 13 1 2 -1] [19 14 1 1 2] 
Feature 1065 - #rectangles = 2: [2 6 5 8 -1] [2 10 5 4 2]
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-02-05 08:49:52 -0600

Seen: 844 times

Last updated: Feb 09 '15