【问题标题】:OpenCV 3.1.0 Assertion failed checkDetectorSize in cv::HOGDescriptor::setSVMDetectorOpenCV 3.1.0 断言在 cv::HOGDescriptor::setSVMDetector 中的 checkDetectorSize 失败
【发布时间】:2016-07-18 23:24:16
【问题描述】:

我正在尝试使用自己的图像训练 SVM,并将其提供给 OpenCV 中的 HOGDescriptor。 训练看起来进行得很顺利,但是当我尝试使用 setSVMDetector 函数将模型提供给 HOGDescriptor 时,它失败了。 训练代码

    Mat trainingImages = new Mat();
    Mat trainingLables = new Mat();

    String personsPath = "C:\INRIAPerson\\INRIAPerson\\96X160H96\\Train\\pos";

    for (File file : new File(personsPath).listFiles()) {
        if(file.isFile()){
            Mat img = Imgcodecs.imread(file.getPath());
            Mat newImg = new Mat();
            Imgproc.cvtColor(img, newImg, Imgproc.COLOR_BGR2GRAY);
            newImg = newImg.reshape(1,1);

            trainingImages.push_back(newImg);
            trainingLables.push_back(Mat.ones(new Size(1,1), CvType.CV_32SC1));
        }
    }


    String nonPersonsPath = "C:\\NRIAPerson\\INRIAPerson\\train_64x128_H96\\neg";
    for (File file : new File(nonPersonsPath).listFiles()) {
        if(file.isFile()){
            Mat img = Imgcodecs.imread(file.getPath());
            Mat newImg = new Mat();
            Imgproc.cvtColor(img, newImg, Imgproc.COLOR_BGR2GRAY);

            Imgproc.resize(newImg, newImg, new Size(160 , 96));
            newImg = newImg.reshape(1,1);

            trainingImages.push_back(newImg);
            trainingLables.push_back(Mat.zeros(new Size(1,1), CvType.CV_32SC1));
        }
    }

    trainingImages.convertTo(trainingImages, CvType.CV_32FC1);

    SVM trainer = SVM.create();
    trainer.setKernel(SVM.LINEAR);
    trainer.train(trainingImages, Ml.ROW_SAMPLE, trainingLables);

    HOGDescriptor hog = new HOGDescriptor(new Size(160, 96), new Size(8,8), new Size(4,4), new Size(4,4), 9);
    Mat supportVector = trainer.getSupportVectors();
    hog.setSVMDetector(supportVector);

错误信息

libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
OpenCV Error: Assertion failed (checkDetectorSize()) in cv::HOGDescriptor::setSVMDetector, file C:\builds\master_PackSlaveAddon-win64-vc12-static\opencv\modules\objdetect\src\hog.cpp, line 117
Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: C:\builds\master_PackSlaveAddon-win64-vc12-static\opencv\modules\objdetect\src\hog.cpp:117: error: (-215) checkDetectorSize() in function cv::HOGDescriptor::setSVMDetector
]
    at org.opencv.objdetect.HOGDescriptor.setSVMDetector_0(Native Method)
    at org.opencv.objdetect.HOGDescriptor.setSVMDetector(HOGDescriptor.java:302)
    at feature.extraction.App.main(App.java:86)

我不知道 libpng 警告是否与它有关。 快把我逼疯了 有人知道吗?

【问题讨论】:

    标签: java opencv opencv3.0


    【解决方案1】:

    我想通了。我做错了几件事

    1. 我正在使用图像而不是 features 进行训练
    2. 我忘记在支持向量中添加-rho

    首先我创建了一个2d float array。使用 HOGDescriptor 类中的 compute 函数填充图像的特征。用数组训练 SVM。训练结束后,我使用getDecisionFunction 函数获取rho 并将其附加到supportvector

    【讨论】:

      猜你喜欢
      • 2015-09-03
      • 2014-10-21
      • 1970-01-01
      • 2023-03-22
      • 2015-05-20
      • 2017-12-24
      • 2021-02-26
      • 2020-04-03
      • 1970-01-01
      相关资源
      最近更新 更多