Training custom SVM to use with HOGDescriptor in OpenCV

前端 未结 3 728
盖世英雄少女心
盖世英雄少女心 2020-11-30 07:25

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

3条回答
  •  抹茶落季
    2020-11-30 07:34

    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 w

        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...

提交回复
热议问题