I\'m creating an application for classifying humans in images of urban setting.
I train a classifer in following manner:
int main (int argc, char **a
I managed to get adaBoost working by adapting the code from the SVM documentation. The only trick was ensuring there was enough sample data (>= 11).
From the blog where your code is copied from:
NOTE: For a very strange reason the OpenCV implementation does not work with less than 11 samples.
// Training data
float labels[11] = { 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0};
Mat labelsMat(11, 1, CV_32FC1, labels);
float trainingData[11][2] = {
{501, 10}, {508, 15},
{255, 10}, {501, 255}, {10, 501}, {10, 501}, {11, 501}, {9, 501}, {10, 502}, {10, 511}, {10, 495} };
Mat trainingDataMat(11, 2, CV_32FC1, trainingData);
// Set up SVM's parameters
CvSVMParams params;
params.svm_type = CvSVM::C_SVC;
params.kernel_type = CvSVM::LINEAR;
params.term_crit = cvTermCriteria(CV_TERMCRIT_ITER, 100, 1e-6);
// Train a SVM classifier
CvSVM SVM;
SVM.train(trainingDataMat, labelsMat, Mat(), Mat(), params);
// Train a boost classifier
CvBoost boost;
boost.train(trainingDataMat,
CV_ROW_SAMPLE,
labelsMat);
// Test the classifiers
Mat testSample1 = (Mat_<float>(1,2) << 251, 5);
Mat testSample2 = (Mat_<float>(1,2) << 502, 11);
float svmResponse1 = SVM.predict(testSample1);
float svmResponse2 = SVM.predict(testSample2);
float boostResponse1 = boost.predict(testSample1);
float boostResponse2 = boost.predict(testSample2);
std::cout << "SVM: " << svmResponse1 << " " << svmResponse2 << std::endl;
std::cout << "BOOST: " << boostResponse1 << " " << boostResponse2 << std::endl;
// Output:
// > SVM: -1 1
// > BOOST: -1 1