Ask Your Question

Revision history [back]

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]