I\'m trying to train my own detector for use with OpenCV::HOGDescriptor but I\'m having trouble making the existing HOGDescriptor work with my newly trained SVM.
I
I was struggling with the same problem. Searching forums I have found, that the detector cannot be trained using CvSVM (I don't know the reason). I used LIBSVM for training the the detector. Here is the code to extract the detector for HOGDescriptor.setSVMDetector( w): For data details see LIBSVM documentation/header. I did all the training in C++, filling the LIBSVM training data from CV to LIBSVM; the code below extracts the detector vector needed for cv::HOGDescriptor. The w parameter is std::vector
const double * const *sv_coef = model.sv_coef;
const svm_node * const *SV = model.SV;
int l = model.l;
model.label;
const svm_node* p_tmp = SV[0];
int len = 0;
while( p_tmp->index != -1 )
{
len++;
p_tmp++;
}
w.resize( len+1 );
for( int i=0; iindex != -1 )
{
w[p->index-1] += float(svcoef * p->value);
p++;
}
}
w[len] = float(-model.rho[0]);
Hope this helps...