如何在使用 SVM 分类器检测到的对象周围突出显示(绘制 boundingRect/circle)

How to highlight(draw boundingRect/circle) around the object detected by using SVM classifier

我已经成功地训练了 SVM 分类器,现在我想测试一张由真菌孢子组成的图像。如何使用分类器进行检测并在检测到的真菌孢子周围绘制边界矩形/圆圈。测试图片:https://drive.google.com/file/d/0B7yRjtOGywg7c3p0T0J4d0xMX0k/view?usp=sharing 提前致谢

 Mat classes;//(PosSamples+NagSamples, 1, CV_32FC1); 
    Mat trainingData;//(PosSample+NagSample, imgWidth*imgHeight,CV_32FC1 );

    Mat trainingImages;
    vector<int> trainingLabels;

                 for (int pimageNum = 0; pimageNum < 359; pimageNum++)
                  {
                // reading Positive Images
                        trainingImages.push_back(posImage);
              for (int i = 0; i < 50; i++)
                        trainingLabels.push_back(1.0);
                }
                for (int nimageNum = 0; nimageNum < 171; nimageNum++)
                  {
                // reading Nagative Images
                        trainingImages.push_back(nagImage);
              for (int i = 0; i < 50; i++)
                        trainingLabels.push_back(0.0);
                }
                 Mat(trainingImages).copyTo(trainingData);
                    trainingData.convertTo(trainingData, CV_32FC1);
                    Mat(trainingLabels).copyTo(classes);

                 FileStorage fs0("D:\classifier.yml", FileStorage::WRITE);
                    fs0 << "TrainingData" << trainingData;
                    fs0 << "classes" << classes;
                    fs0.release();

                 CvSVMParams SVM_params;
                    SVM_params.svm_type = CvSVM::C_SVC;
                    SVM_params.kernel_type = CvSVM::LINEAR;
                    SVM_params.degree = 0;
                    SVM_params.gamma = 1;
                    SVM_params.coef0 = 0;
                    SVM_params.C = 1;
                    SVM_params.nu = 0;
                    SVM_params.p = 0;
                    SVM_params.term_crit = cvTermCriteria(CV_TERMCRIT_ITER, 1000, 0.01);
                    //Train SVM
                    CvSVM svmClassifier(trainingData, Classes, Mat(), Mat(),SVM_params);

    //////////////////////////////// image size 50x50 ////////////////////////////
        classifier.yml file

        TrainingData: !!opencv-matrix
           rows: 26500
           cols: 50
        classes: !!opencv-matrix
           rows: 26500
           cols: 1

您可以在 HOGDescriptor::setSVMDetector() 中使用 SVM 分类器。 使用 peopledetector.cpp 示例代码在检测到的对象周围绘制 boundingRect/Circles。