HOG setSVMDetector slow
I'm using HOG with custom svm. I've used https://github.com/opencv/opencv/blob/master/samples/cpp/train_HOG.cpp but my feature vector has 2268 features and get_svm_detector() give me 2269 support vectors, this don't give me error but hog.detectMultiScale is very slow ( ~ 6 s), why?
With svmLight I get 2268 support vectors and hog.detectMultiScale takes about ~64 ms.
I Add the code:
Ptr<SVM> svm;
Ptr<TrainData> trainData = TrainData::loadFromCSV("./trainData.csv");
svm = SVM::create();
svm->setType(SVM::C_SVC);
svm->setKernel(SVM::LINEAR);
svm->setTermCriteria(TermCriteria(TermCriteria::MAX_ITER + TermCriteria::EPS, (int)1000, 1e-3));
svm->trainAuto(ejemplosEntrenamiento,10,SVM::getDefaultGrid(SVM::C),SVM::getDefaultGrid(SVM::GAMMA),SVM::getDefaultGrid(SVM::P),SVM::getDefaultGrid(SVM::NU),SVM::getDefaultGrid(SVM::COEF),SVM::getDefaultGrid(SVM::DEGREE),true svm->trainAuto(trainData,10,SVM::getDefaultGrid(SVM::C),SVM::getDefaultGrid(SVM::GAMMA),SVM::getDefaultGrid(SVM::P),SVM::getDefaultGrid(SVM::NU),SVM::getDefaultGrid(SVM::COEF),SVM::getDefaultGrid(SVM::DEGREE),true );
svm->save("model.yml");
In other class:
HOGDescriptor hog;
Ptr<SVM> svm = StatModel::load<SVM>( "model.yml" );
Ptr<SVM> svm = StatModel::load<SVM>( "clasificador.yml" );
vector< float > hog_detector;
// 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 );
hog_detector.clear();
hog_detector.resize(sv.cols + 1);
memcpy(&hog_detector[0], sv.ptr(), sv.cols*sizeof(hog_detector[0]));
hog_detector[sv.cols] = (float)-rho;
hog.setSVMDetector( hog_detector );
// Then, it take me about 6 s!!
hog.detectMultiScale(img, detections, thresholdDetection, winStride, padding);