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