Ask Your Question
1

HOG-Descriptor Malloc error

asked 2018-01-23 02:47:12 -0600

teenvan95 gravatar image

I am trying to calculate the hog descriptors of a vector of images but keep getting the following error:

HOG-Descriptor(76121,0x70000f807000) malloc: * error for object 0x106f55c10: incorrect checksum for freed object - object was probably modified after being freed. * set a breakpoint in malloc_error_break to debug

My Code for your reference:

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);
        data.push_back(descriptors);
    }
}

calcDescriptors(img_list, data);
cout<<"Creating and training dtree\n";
Ptr<ml::DTrees> model = ml::DTrees::create();
model->train(ml::TrainData::create(data, ml::ROW_SAMPLE, labels));
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2018-01-23 02:59:22 -0600

berak gravatar image

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
    }
}
edit flag offensive delete link more

Comments

Thanks for the answer. Now I do have a data Mat object of size 388 x 7020 but I get the following error: libc++abi.dylib: terminating with uncaught exception of type std::length_error: allocator<t>::allocate(size_t n) 'n' exceeds maximum supported size

teenvan95 gravatar imageteenvan95 ( 2018-01-23 03:16:25 -0600 )edit

On this line : ->

Ptr<ml::DTrees> model = ml::DTrees::create();
model->train(ml::TrainData::create(data, ml::ROW_SAMPLE, labels));
teenvan95 gravatar imageteenvan95 ( 2018-01-23 03:22:54 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-01-23 02:47:12 -0600

Seen: 401 times

Last updated: Jan 23 '18