Hello everybody,
In following code I read in my webcam and want to detect face. Unfortunately it does not work. I commented some parts of the end out and I have NO problems only reading in the cam. But the whole code gives the error like below.
Here is the code:
include "opencv2/objdetect/objdetect.hpp"
include "opencv2/highgui/highgui.hpp"
include "opencv2/imgproc/imgproc.hpp"
include <iostream>
include <stdio.h>
using namespace std; using namespace cv;
Mat detectFace(Mat src);
int main() { VideoCapture cap(0); namedWindow("window1", 1);
while (1)
{
Mat frame;
cap >> frame;
frame = detectFace(frame);
imshow("window1", frame);
// Press 'c' to escape
if (waitKey(1) == 'c') break;
}
waitKey(0);
return 0;
}
Mat detectFace(Mat image) { // Load Face cascade (.xml file) CascadeClassifier face_cascade("haarcascade_frontalface_alt2.xml");
// Detect faces
std::vector<Rect> faces;
face_cascade.detectMultiScale(image, faces, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(30, 30));
////// 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(image, center, Size(faces[i].width*0.5, faces[i].height*0.5), 0, 0, 360, Scalar(255, 0, 255), 4, 8, 0);
}
return image;
}
This is the error message: OpenCV Error: Assertion failed (axes.width >= 0 && axes.height >= 0 && thickness <= 255 && 0 <= shift && shift <= XY_SHIFT) in cv::ellipse, file C:\builds\master_PackSlave-win32 -vc12-shared\opencv\modules\imgproc\src\drawing.cpp, line 1772
I am looking forward for your support and help. Thank you!