OpenCV 3.1.0 Assertion failed checkDetectorSize in cv::HOGDescriptor::setSVMDetector

just_trying_stuff

I'm trying to train SVM with my own images and feed that to the HOGDescriptor in OpenCV. The training looks to be going well, but when I try to give the model to the HOGDescriptor with the setSVMDetector function it fails. Code for training

    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);

The error message

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)

I don't know if the libpng warning's have anything to do with it. It's driving me crazy does anybody have an idea?

just_trying_stuff

I figured it out. I was doing a couple thing wrong

  1. I was training with images and not features
  2. I forgot adding -rho to the supportvector

First I created a 2d float array. Populated it with the features of the image by using the compute function from the HOGDescriptor class. Trained the SVM with the array. After the training I used the getDecisionFunction function to get the rho and appended that to the supportvector.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

OpenCV Assertion failed: (-215:Assertion failed) npoints >= 0 && (depth == CV_32F || depth == CV_32S)

From Dev

OpenCV Assertion Failed error: (-215) scn == 3 || scn == 4 in function cv::cvtColor works ALTERNATE times

From Dev

OpenCV Assertion Failed error: (-215) scn == 3 || scn == 4 in function cv::cvtColor works ALTERNATE times

From Dev

OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cv:: cvtColor, file ..\..\..\..\opencv\modules\imgproc\src\color.cpp, line 3737

From Dev

OpenCV Error: Assertion failed (src1.size == dst.size && dst.type() == CV_8U) in cvInRangeS

From Dev

OpenCV with Python error - Assertion failed ((mask.type() == CV_8UC1 || mask.type() == CV_8SC1)) in binary_op

From Dev

Python-OpenCV cv2 OpenCV Error: Assertion failed (scn == 3 || scn == 4) in unknown function, file ..\..\..\modules\imgproc\src\color.cpp

From Dev

Python-OpenCV cv2 OpenCV Error: Assertion failed (scn == 3 || scn == 4) in unknown function, file ..\..\..\modules\imgproc\src\color.cpp

From Dev

OpenCV Assertion failed with ROI

From Dev

OpenCV calibrateCamera() Assertion failed

From Dev

OpenCV: Assertion failed with drawContours()

From Dev

OpenCV calibrateCamera() Assertion failed

From Dev

Opencv Error:Assertion failed

From Dev

OpenCV:Assertion Failed

From Dev

Assertion failed (scn == 3 || scn == 4) in void cv::cvtColor(cv::InputArray Android

From Dev

OpenCV Python Error Assertion failed (scn == 3 || scn == 4)

From Dev

openCV Error: Assertion failed (scn == 3 || scn == 4)

From Dev

openCV Error: Assertion failed (scn == 3 || scn == 4)

From Dev

cv::erode causes error: OpenCV Error: Assertion failed (m.dims >= 2) in Mat

From Dev

cv::erode causes error: OpenCV Error: Assertion failed (m.dims >= 2) in Mat

From Dev

Copying cv::Mat to another creates "assertion failed 0 <= _colRange.start && .."

From Dev

C++ & OpenCV assertion failed

From Dev

opencv 3.0.0 alpha with Python 3 failed to import cv2

From Dev

opencv 3.0.0 alpha with Python 3 failed to import cv2

From Dev

OpenCV: HOGDescriptor.compute

From Dev

OpenCV: HOGDescriptor.compute

From Dev

OpenCV Error: Assertion failed (size.width>0 && size.height>0) simple code

From Java

src.type() == CV_8UC1 assertion failed when deskewing image

From Dev

OpenCV error: Assertion failed. What to do?

Related Related

  1. 1

    OpenCV Assertion failed: (-215:Assertion failed) npoints >= 0 && (depth == CV_32F || depth == CV_32S)

  2. 2

    OpenCV Assertion Failed error: (-215) scn == 3 || scn == 4 in function cv::cvtColor works ALTERNATE times

  3. 3

    OpenCV Assertion Failed error: (-215) scn == 3 || scn == 4 in function cv::cvtColor works ALTERNATE times

  4. 4

    OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cv:: cvtColor, file ..\..\..\..\opencv\modules\imgproc\src\color.cpp, line 3737

  5. 5

    OpenCV Error: Assertion failed (src1.size == dst.size && dst.type() == CV_8U) in cvInRangeS

  6. 6

    OpenCV with Python error - Assertion failed ((mask.type() == CV_8UC1 || mask.type() == CV_8SC1)) in binary_op

  7. 7

    Python-OpenCV cv2 OpenCV Error: Assertion failed (scn == 3 || scn == 4) in unknown function, file ..\..\..\modules\imgproc\src\color.cpp

  8. 8

    Python-OpenCV cv2 OpenCV Error: Assertion failed (scn == 3 || scn == 4) in unknown function, file ..\..\..\modules\imgproc\src\color.cpp

  9. 9

    OpenCV Assertion failed with ROI

  10. 10

    OpenCV calibrateCamera() Assertion failed

  11. 11

    OpenCV: Assertion failed with drawContours()

  12. 12

    OpenCV calibrateCamera() Assertion failed

  13. 13

    Opencv Error:Assertion failed

  14. 14

    OpenCV:Assertion Failed

  15. 15

    Assertion failed (scn == 3 || scn == 4) in void cv::cvtColor(cv::InputArray Android

  16. 16

    OpenCV Python Error Assertion failed (scn == 3 || scn == 4)

  17. 17

    openCV Error: Assertion failed (scn == 3 || scn == 4)

  18. 18

    openCV Error: Assertion failed (scn == 3 || scn == 4)

  19. 19

    cv::erode causes error: OpenCV Error: Assertion failed (m.dims >= 2) in Mat

  20. 20

    cv::erode causes error: OpenCV Error: Assertion failed (m.dims >= 2) in Mat

  21. 21

    Copying cv::Mat to another creates "assertion failed 0 <= _colRange.start && .."

  22. 22

    C++ & OpenCV assertion failed

  23. 23

    opencv 3.0.0 alpha with Python 3 failed to import cv2

  24. 24

    opencv 3.0.0 alpha with Python 3 failed to import cv2

  25. 25

    OpenCV: HOGDescriptor.compute

  26. 26

    OpenCV: HOGDescriptor.compute

  27. 27

    OpenCV Error: Assertion failed (size.width>0 && size.height>0) simple code

  28. 28

    src.type() == CV_8UC1 assertion failed when deskewing image

  29. 29

    OpenCV error: Assertion failed. What to do?

HotTag

Archive