OpenCV HOG+SVM: assertion failed checkDetectorSize()

OpenCV HOG+SVM: assertion failed checkDetectorSize()

本文关键字:checkDetectorSize failed assertion HOG+SVM OpenCV      更新时间:2023-10-16

当我尝试将自己的SVM检测器设置为openCV中的hog::setSVMDetector(Detector)方法时,我在c ++中的openCV中遇到了问题。

我遵循以下过程 SVM 分类器 基于 HOG 功能在 OpenCV 中进行"对象检测",我被困在步骤 3 上。

我正在使用 openCV 3.0,它目前是在 SVM 中构建的。这就是我训练和构建探测器的方式:

火车

svm = SVM::create();
svm->setType(type);
svm->setKernel(kernel);
svm->setC(C);
if (kernel == SVM::LINEAR) {
    svm->setDegree(1);
} else if (kernel == SVM::POLY) {
    svm->setDegree(3);
}
svm->train(trainingSamples, ml::ROW_SAMPLE, labels);

建筑探测器

vector<float> alpha;
vector<float> svidx;
vector<float> model;
// Getting Support Vectors
Mat svs = svm->getSupportVectors();
double rho = svm->getDecisionFunction(0, alpha, svidx);
    // Computing w in primal form
for (int i = 0; i < svidx.size(); i++) {
    model.push_back(svs.at<float>(i, 0) * alpha.at(i));
    for (int j = 1; j < svs.cols; j++) {
        model.at(i) += svs.at<float>(i, j) * alpha.at(i);
    }
}
//   Adding rho
    model.push_back(rho);
    return model;

当我尝试将上述模型馈送到以下位置时,会发生错误:

hog.setDetector(model); 

OpenCV 错误:断言失败 (checkDetectorSize()) in setSVMDetector, file /home/dario/Desktop/opencv-3.0.0-rc1/modules/objdetect/src/hog.cpp, 第 115 行终止在抛出 的实例后调用 'cv::Exception' what(): /home/dario/Desktop/opencv-3.0.0-rc1/modules/objdetect/src/hog.cpp:115: 错误: (-215) 检查函数集中的检测器大小() SVMDetector

知道我做错了什么吗?

我通过将上面的代码重写为

    Ptr<SVM> svm;
    HOGDescriptor my_hog;
    ...
    // Load the trained SVM.
    svm = StatModel::load<SVM>( "model.yml" );
    // Set the trained svm to my_hog
    vector< float > hog_detector;
    get_svm_detector( svm, hog_detector );
    my_hog.setSVMDetector( hog_detector );
相关文章:
  • 没有找到相关文章