Ask Your Question

OpenCV 3 Boost train help

asked 2016-04-05 16:38:39 -0600

Killerwife gravatar image

updated 2016-04-06 09:15:31 -0600

I am trying to train my own AdaBoost for object detection. I have compiled this code from examples but I encountered a problem.

cv::Mat* data=nullptr;
cv::Mat* responses = nullptr;
cv::Ptr<cv::ml::Boost> boost = cv::ml::Boost::create();
boost->train(cv::Mat(*data), cv::ml::ROW_SAMPLE, cv::Mat(*responses));

This error pops up when I use the train function "Expression: vector subscript out of range" It occurs on this line: err += wval*(result[i] != w->cat_responses[si]); in opencv_ml310d.dll!cv::ml::DTreesImplForBoost::updateWeightsAndTrim(int treeidx, std::vector<int,std::allocator<int> > & sidx) Line 235 C++

My data and responses cv::Mats have the exact same amount of rows. Responses is a cv::Mat with one collumn, containing a 0 or 1 depending on the class of each sample. Data mat is a cv::Mat of images I am trying to train on, each containing a person if its a positive sample. The format of the data cv::Mat consists of one image in each row of the cv::Mat.

I have compiled the latest opencv 3 from GitHub and to my knowledge it was compiled correctly thus far. Any ideas where I should look for an error?

Sample Data (using cv::FileStorage) in yml Sample Data

edit retag flag offensive close merge delete


can you try to find some simple (synthetic) test data, to reproduce your problem ?

berak gravatar imageberak ( 2016-04-06 06:40:53 -0600 )edit

I added a link to some uploaded sample data.

Killerwife gravatar imageKillerwife ( 2016-04-06 09:15:53 -0600 )edit

indeed, w->cat_responses was never initialized.

berak gravatar imageberak ( 2016-04-06 09:36:16 -0600 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2016-04-06 09:47:09 -0600

berak gravatar image

are you trying to do a classification or regression ?


only gets correctly initialized here , if you use integer responses.

edit flag offensive delete link more


I am trying to do a classification. So I need to convert responses array to integers?

Killerwife gravatar imageKillerwife ( 2016-04-06 11:20:31 -0600 )edit

yes, indeed.

berak gravatar imageberak ( 2016-04-06 11:24:22 -0600 )edit

Yes, that fixed the problem. Now I need to figure out why my XML weights are only 0 and 0. but thats a different issue completely. Thank you.

Killerwife gravatar imageKillerwife ( 2016-04-06 11:38:20 -0600 )edit

Question Tools

1 follower


Asked: 2016-04-05 16:38:39 -0600

Seen: 923 times

Last updated: Apr 06 '16