# Revision history [back]

### OpenCV 3 Boost train help

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;
parser.toMat(&data,&responses);
cv::Ptr<cv::ml::Boost> boost = cv::ml::Boost::create();
boost->setBoostType(cv::ml::Boost::DISCRETE);
boost->setWeakCount(100);
boost->setWeightTrimRate(0.95);
boost->setMaxDepth(2);
boost->setUseSurrogates(false);
boost->setPriors(cv::Mat());
boost->train(cv::Mat(*data), cv::ml::ROW_SAMPLE, cv::Mat(*responses));
boost->save("trainedBoost.xml");


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?

### OpenCV 3 Boost train help

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;
parser.toMat(&data,&responses);
cv::Ptr<cv::ml::Boost> boost = cv::ml::Boost::create();
boost->setBoostType(cv::ml::Boost::DISCRETE);
boost->setWeakCount(100);
boost->setWeightTrimRate(0.95);
boost->setMaxDepth(2);
boost->setUseSurrogates(false);
boost->setPriors(cv::Mat());
boost->train(cv::Mat(*data), cv::ml::ROW_SAMPLE, cv::Mat(*responses));
boost->save("trainedBoost.xml");


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