Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

2 things here:

1) you're using the same descriptors vector over and over, and data.push_back() won't make a deep copy, so, when you leave the function, data is invalid (pointing to a local array)

2) if you wrap a vector with a Mat, it comes out as a single column, while you need a single row for the ml training

so:

void calcDescriptors(std::vector<Mat> &img_list, Mat &data){
    HOGDescriptor h;
    h.winSize = Size(128, 112);
    vector<float> descriptors;
    for(size_t k=0; k<img_list.size(); k++){
        h.compute(img_list[k], descriptors);
        Mat feature(descriptors, true); // "really" copy data
        data.push_back(feature.reshape(1,1)); // as a row
    }
}