I'm using OpenCV 3.4.3 with C++ and i try to train my svm using TrainHOG.exe(you can find it on opencv docs). I've prepared dataset(combination of INRIA person dataset and a few more my own cropped images) but results of svm i get using params(like below) gives me too many false positives:
Ptr< SVM > svm = SVM::create();
/* Default values to train SVM */
svm->setCoef0(0.0);
svm->setDegree(3);
svm->setTermCriteria(TermCriteria(CV_TERMCRIT_ITER + CV_TERMCRIT_EPS, 1000, 1e-3));
svm->setGamma(0);
svm->setKernel(SVM::LINEAR);
svm->setNu(0.5);
svm->setP(0.1); // for EPSILON_SVR, epsilon in loss function?
svm->setC(0.01); // From paper, soft classifier
svm->setType(SVM::EPS_SVR); // C_SVC; // EPSILON_SVR; // may be also NU_SVR; // do regression task
svm->train(train_data, ROW_SAMPLE, labels);
So i've changed train to trainAuto and it gives me some errors:
and then crashes with this error:
I've checked that lines in svm.cpp (https://github.com/opencv/opencv/blob/master/modules/ml/src/svm.cpp) and the last assert giving me error is here:
double getDecisionFunction(int i, OutputArray _alpha, OutputArray _svidx ) const CV_OVERRIDE
{
CV_Assert( 0 <= i && i < (int)decision_func.size());
const DecisionFunc& df = decision_func[i];
int count = getSVCount(i);
Mat(1, count, CV_64F, (double*)&df_alpha[df.ofs]).copyTo(_alpha);
Mat(1, count, CV_32S, (int*)&df_index[df.ofs]).copyTo(_svidx);
return df.rho;
}
Since i = 0 (in TrainHog.exe):
vector< float > get_svm_detector(const Ptr< SVM >& svm){
// get the support vectors
Mat sv = svm->getSupportVectors();
const int sv_total = sv.rows;
// get the decision function
Mat alpha, svidx;
double rho = svm->getDecisionFunction(0, alpha, svidx);
CV_Assert(alpha.total() == 1 && svidx.total() == 1 && sv_total == 1);
CV_Assert((alpha.type() == CV_64F && alpha.at<double>(0) == 1.) ||
(alpha.type() == CV_32F && alpha.at<float>(0) == 1.f));
CV_Assert(sv.type() == CV_32F);
vector< float > hog_detector(sv.cols + 1);
memcpy(&hog_detector[0], sv.ptr(), sv.cols * sizeof(hog_detector[0]));
hog_detector[sv.cols] = (float)-rho;
return hog_detector;
}
assertion fails due second condition (i < (int)decision_func.size()), but i don't know what it means and still don't know what am i doing wrong.
Sorry for my bad eng and thanks in advance.