Hi
I'm trying to use chapter 8 of (mastering opencv ) book to detect face and eyes .
it works fine for detecting faces , my problem is when that I call this function :
void detectBothEyes(const Mat &face, CascadeClassifier &eyeCascade1, CascadeClassifier &eyeCascade2, Point &leftEye, Point &rightEye, Rect *searchedLeftEye, Rect *searchedRightEye)
this is my main() : and here is the : [code](http://pastie.org/private/06ljezk180mhdidwrlw8rg)
int main()
{
CascadeClassifier faceCascade;
CascadeClassifier eyeCascade1;
CascadeClassifier eyeCascade2;
Rect faceRect;
VideoCapture videoCapture ("m.mp4");
cout << "Face Detection ." << endl;
cout << "Realtime face detection using LBP " << endl;
cout << "Compiled with OpenCV version " << CV_VERSION << endl << endl;
// Load the face and 1 or 2 eye detection XML classifiers.
initDetectors(faceCascade,eyeCascade1,eyeCascade2);
while (1)
{
Mat frame;
videoCapture>> frame;
detectLargestObject(frame, faceCascade, faceRect);
if (faceRect.width > 0)
{
rectangle(frame, faceRect, CV_RGB(255, 255, 0), 2, CV_AA);
}
Mat srcImg;
Mat faceImg = srcImg(faceRect);
Mat gray;
if (faceImg.channels() == 3) {
cvtColor(faceImg, gray, CV_BGR2GRAY);
}
else if (faceImg.channels() == 4) {
cvtColor(faceImg, gray, CV_BGRA2GRAY);
}
else {
// Access the input image directly, since it is already grayscale.
gray = faceImg;
}
Point leftEye, rightEye;
Rect searchedLeftEye, searchedRightEye;
detectBothEyes(gray, eyeCascade1, eyeCascade2, leftEye, rightEye, &searchedLeftEye, &searchedRightEye);
rectangle(frame, rightEye, leftEye, CV_RGB(0, 255, 255), 2);
imshow("video", frame);
// Press 'c' to escape
if (waitKey(20) == 'c') break;
}
return 0;
}
when I run it , throws an exception and this message is displayed :
OpenCV Error: Assertion failed (0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows) in cv::Mat::Mat, file C:\builds\2_4_PackSlave-win64-vc12-shared\opencv\modules\core\src\matrix.cpp, line 323
can you help me please to solve this problem
Thanks
↧