Ask Your Question
0

OpenCv error: Assertion faild (!empty()) in cv::CascadeClassifier::detectMultiScale

asked 2015-10-07 09:48:18 -0600

Mehdi.Am gravatar image

Hi Friends I'm trying to do face detection using OpenCv 3.0.0, I think something is wrong because when I run my project I face this error:

Unhandled exception at at 0x00007FFD630CAB78 in shapeDetection.exe: Microsoft C++ exception: cv::Exception at memory location 0x000000D92794F810.

and in console it's printed:

OpenCv error: Assertion faild (!empty()) in cv::CascadeClassifier::detectMultiScale

I read different posts about it, but none of them could help me. here is my code:

// shapeDetection.cpp : Defines the entry point for the console application. //

#include "stdafx.h"
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include <opencv2\objdetect\objdetect.hpp>
#include <iostream>

using namespace cv;
using namespace std;


    //load face cascade
    CascadeClassifier faceCascade;

void detection(Mat frame)
{
    //Detect faces
    vector<Rect> faces; 
    faceCascade.detectMultiScale(frame,faces,1.1, 3, CV_HAAR_FIND_BIGGEST_OBJECT|CV_HAAR_SCALE_IMAGE,Size(300,300) );

    // Draw circles on the detected faces
    for( int i = 0; i < faces.size(); i++ )
    {
        Point center( faces[i].x + faces[i].width*0.5, faces[i].y + faces[i].height*0.5 );
        ellipse( frame, center, Size( faces[i].width*0.5, faces[i].height*0.5), 0, 0, 360, Scalar( 255, 0, 255 ), 4, 8, 0 );
    }

        imshow("Video",frame);
}

int _tmain(int argc, _TCHAR* argv[])
{

    VideoCapture cap(0);
    if(!cap.isOpened())
        return -1;

    //creating window
    namedWindow("Video",CV_WINDOW_AUTOSIZE);
    faceCascade.load("C:\opencv\sources\data\haarcascades_cuda\haarcascade_frontalface_alt2.xml");

    Mat frame;
    while (1)
    {

        cap.read(frame);
        waitKey(30);
        if(!frame.empty())
        {
            detection(frame);
        }
        else
        {
            cout<<"there is no frame"<<endl;
        }

    }

    return 0;
}
edit retag flag offensive close merge delete

Comments

@berak it's Solved,Thank you so much

Mehdi.Am gravatar imageMehdi.Am ( 2015-10-07 10:28:36 -0600 )edit

i don't recall why there's a haarcascades_cuda and a haarcascades version, but try the non-cuda one.

berak gravatar imageberak ( 2015-10-07 10:31:47 -0600 )edit

sure,It's done dear,Thanks for your solution

Mehdi.Am gravatar imageMehdi.Am ( 2015-10-07 10:35:30 -0600 )edit

@berak I faced this Error too : OpenCV Error: Assertion failed (axes.width >= 0 && axest.height >= 0 && .... How can I solve it?

Mehdi.Am gravatar imageMehdi.Am ( 2015-10-07 12:06:33 -0600 )edit
1

@berak, reason for a cuda and non cuda version is the difference in implementation. The non cuda ones are updated to the traincascade interface and new model structure, but the GPU variant is not able to use those new models yet.

StevenPuttemans gravatar imageStevenPuttemans ( 2015-10-08 06:35:59 -0600 )edit
1

^^ thanks for the highlight !

berak gravatar imageberak ( 2015-10-08 09:01:23 -0600 )edit

@berak so what should I do?

Mehdi.Am gravatar imageMehdi.Am ( 2015-10-09 00:46:53 -0600 )edit
1

one of the assertions here failed

berak gravatar imageberak ( 2015-10-09 01:55:22 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2015-10-07 10:15:13 -0600

berak gravatar image

updated 2015-10-08 09:03:31 -0600

Dear, either use double backslashes in any file path, or single forward slashes.

also, the files in haarcascades_cuda can only be used with the cuda version of CascadeClassifier

edit flag offensive delete link more

Comments

@Mehdi.Am could you accept this answer?

StevenPuttemans gravatar imageStevenPuttemans ( 2015-10-08 06:35:15 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-10-07 09:48:18 -0600

Seen: 3,999 times

Last updated: Oct 08 '15