Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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

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?

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

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?

EDIT: added the -rho, but still the same result. Don't know if I did it right though

Mat hogvector = new Mat();
supportVector.copyTo(hogvector);
hogvector.put(1, supportVector.cols() + 1, -decision);
hog.setSVMDetector(hogvector);

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

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?

EDIT: added the -rho, but still the same result. Don't know if I did it right though

Mat hogvector = new Mat();
supportVector.copyTo(hogvector);
hogvector.put(1, supportVector.cols()         int size = (int)(supportVector.total() + 1, -decision);
hog.setSVMDetector(hogvector);
1) * supportVector.channels();
        float[] temp = new float[size];
        supportVector.get(0, 0, temp);
        temp[temp.length - 1] = (float)-decision;
        MatOfFloat floatvector = new MatOfFloat(temp);

        hog.setSVMDetector(floatvector);

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

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

 HOGDescriptor hog = new HOGDescriptor(new Size(96, 160), new Size(8,8), new Size(4,4), new Size(4,4), 9);

    SVM svm = SVM.create();
    svm.setKernel(SVM.LINEAR);

    MatOfFloat traindata = new MatOfFloat();
    Mat trainingImages = new Mat();
    Mat trainingLables trainlabel = new Mat();

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

"C:\\_small\\pos";
    for (File file : new File(personsPath).listFiles()) {
        if(file.isFile()){
            Mat img = Imgcodecs.imread(file.getPath());
            MatOfFloat descriptors = new MatOfFloat();

            Mat newImg gray = new Mat();
            Imgproc.cvtColor(img, newImg, gray, Imgproc.COLOR_BGR2GRAY);
            newImg = newImg.reshape(1,1);

            trainingImages.push_back(newImg);
            trainingLables.push_back(Mat.ones(new Size(1,1), 
            hog.compute(gray, descriptors);
            traindata.push_back(descriptors);
            trainlabel.push_back(Mat.ones(descriptors.rows(), 1, CvType.CV_32SC1));
        }
    }

     String nonPersonsPath = "C:\\NRIAPerson\\INRIAPerson\\train_64x128_H96\\neg";
personsPathneg = "C:\\_small\\neg";
    for (File file : new File(nonPersonsPath).listFiles()) File(personsPathneg).listFiles()) {
        if(file.isFile()){
            Mat img = Imgcodecs.imread(file.getPath());
            MatOfFloat descriptors = new MatOfFloat();

            Mat newImg gray = new Mat();
            Imgproc.cvtColor(img, newImg, gray, Imgproc.COLOR_BGR2GRAY);

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

            trainingImages.push_back(newImg);
            trainingLables.push_back(Mat.zeros(new Size(1,1), 160));

            hog.compute(gray, descriptors);
            traindata.push_back(descriptors);
            trainlabel.push_back(Mat.zeros(descriptors.rows(), 1, CvType.CV_32SC1));
        }
    }

    trainingImages.convertTo(trainingImages, CvType.CV_32FC1);

    SVM trainer = SVM.create();
    trainer.setKernel(SVM.LINEAR);
    trainer.train(trainingImages, svm.train(traindata, 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);
trainlabel);

    Mat supportVector = trainer.getSupportVectors();
    hog.setSVMDetector(supportVector);
svm.getSupportVectors();

    Mat alpha = new Mat();
    Mat svidx = new Mat();
    double rho = svm.getDecisionFunction(0, alpha, svidx);

    int size = (int)(supportVector.total() + 1) * supportVector.channels();
    float[] temp = new float[size];

    supportVector.get(0, 0, temp);
    temp[temp.length - 1] = (float)-rho;

    MatOfFloat floatvector = new MatOfFloat(temp);

    if(hog.checkDetectorSize()){
        hog.setSVMDetector(floatvector);
    }

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?

EDIT: added the -rho, Edit3: Changed the code to train the features (thanks to berak) but still I get the same result. Don't know error message. The error message points to hog.cpp line 117 the assert that is being called is CV_Assert(checkDetectorSize()); I call the java variant of this function at the end to check if I did it's true and it right though always returns true So what is the difference between the c++ checkDetectorSize and the java one.

        int size = (int)(supportVector.total() + 1) * supportVector.channels();
        float[] temp = new float[size];
        supportVector.get(0, 0, temp);
        temp[temp.length - 1] = (float)-decision;
        MatOfFloat floatvector = new MatOfFloat(temp);

        hog.setSVMDetector(floatvector);

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

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

    HOGDescriptor hog = new HOGDescriptor(new Size(96, 160), new Size(8,8), new Size(4,4), new Size(4,4), 9);

    SVM svm = SVM.create();
    svm.setKernel(SVM.LINEAR);

    MatOfFloat traindata = new MatOfFloat();
    Mat trainlabel = new Mat();

    String personsPath = "C:\\_small\\pos";
    for (File file : new File(personsPath).listFiles()) {
        if(file.isFile()){
            Mat img = Imgcodecs.imread(file.getPath());
            MatOfFloat descriptors = new MatOfFloat();

            Mat gray = new Mat();
            Imgproc.cvtColor(img, gray, Imgproc.COLOR_BGR2GRAY);

            hog.compute(gray, descriptors);
            traindata.push_back(descriptors);
            trainlabel.push_back(Mat.ones(descriptors.rows(), 1, CvType.CV_32SC1));
        }
    }

    String personsPathneg = "C:\\_small\\neg";
    for (File file : new File(personsPathneg).listFiles()) {
        if(file.isFile()){
            Mat img = Imgcodecs.imread(file.getPath());
            MatOfFloat descriptors = new MatOfFloat();

            Mat gray = new Mat();
            Imgproc.cvtColor(img, gray, Imgproc.COLOR_BGR2GRAY);
            Imgproc.resize(gray, gray, new Size(96 , 160));

            hog.compute(gray, descriptors);
            traindata.push_back(descriptors);
            trainlabel.push_back(Mat.zeros(descriptors.rows(), 1, CvType.CV_32SC1));
        }
    }

    svm.train(traindata, Ml.ROW_SAMPLE, trainlabel);

    Mat supportVector = svm.getSupportVectors();

    Mat alpha = new Mat();
    Mat svidx = new Mat();
    double rho = svm.getDecisionFunction(0, alpha, svidx);

    int size = (int)(supportVector.total() + 1) * supportVector.channels();
    float[] temp = new float[size];

    supportVector.get(0, 0, temp);
    temp[temp.length - 1] = (float)-rho;

    MatOfFloat floatvector = new MatOfFloat(temp);

    if(hog.checkDetectorSize()){
        hog.setSVMDetector(floatvector);
    }

The error message

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?

Edit3: Changed the code to train the features (thanks to berak) but still I get the same error message. The error message points to hog.cpp line 117 the assert that is being called is CV_Assert(checkDetectorSize()); I call the java variant of this function at the end to check if it's true and it always returns true So what is the difference between the c++ checkDetectorSize and the java one.