I'm building a face and eye detecting program using OpenCV 3.1 using Visual Studio 2015. I've changed the sample code provided to suit my purposes. The function definition is given below.
void detectAndDisplay(Mat frame)
{
std::vector<Rect> faces, eyes;
Mat frame_gray, crop, gray;
cvtColor(frame, frame_gray, COLOR_BGR2GRAY);
equalizeHist(frame_gray, frame_gray);
// Detect faces and eyes
face_cascade.detectMultiScale(frame_gray, faces, 1.1, 2, 0 | CASCADE_SCALE_IMAGE, Size(40, 40));
size_t ic = 0; // ic is index of current element
unsigned long ac = 0; // ac is area of current element
size_t ib = 0; // ib is index of biggest element
unsigned long ab = 0; // ab is area of biggest element
for (ic = 0; ic < faces.size(); ic++) // Iterate through all current elements (detected faces)
{
ac = faces[ic].area();
ab = faces[ib].area();
if (ac > ab)
ib = ic;
}
crop = frame(faces[ib]);
cvtColor(crop, gray, COLOR_BGR2GRAY);
equalizeHist(gray, gray);
eye_cascade.detectMultiScale(gray, eyes, 1.1, 2, 0 | CASCADE_SCALE_IMAGE, Size(10, 10));
Point Ept1, Ept2;
for (int i = 0; i < eyes.size(); ++i)
{
Ept1.x = eyes[i].x;
Ept1.y = eyes[i].y;
Ept2.x = eyes[i].x + eyes[i].width;
Ept2.y = eyes[i].y + eyes[i].height;
rectangle(frame, Ept1, Ept2, Scalar(0, 255, 0), 2, 8, 0);
}
namedWindow("original", WINDOW_NORMAL);
imshow("original", frame);
}
The cascades load and are located in the source folder. The program worked fine before I added the eye detection feature.
Now the following happens every time I start debugging the code: Video Capture begins and in less than a second the screen freezes, rendering the program unresponsive. No features have been detected by the program at this point.
Closing the console window turns the whole screen blank for a moment. However of note are the exit codes of the program. There is no other information that I have that I could possibly use to understand what is going wrong.
The thread 0x2f54 has exited with code 0 (0x0).
The thread 0x2a5c has exited with code 0 (0x0).
The thread 0x850 has exited with code 0 (0x0).
The thread 0x2a14 has exited with code -1073741510 (0xc000013a).
The thread 0x21e0 has exited with code -1073741510 (0xc000013a).
The thread 0xbe4 has exited with code -1073741510 (0xc000013a).
The thread 0x338c has exited with code -1073741510 (0xc000013a).
The thread 0x16ac has exited with code -1073741510 (0xc000013a).
The thread 0x26a8 has exited with code -1073741510 (0xc000013a).
The thread 0x2a54 has exited with code -1073741510 (0xc000013a).
The thread 0x1e14 has exited with code -1073741510 (0xc000013a).
The thread 0x2f60 has exited with code -1073741510 (0xc000013a).
The thread 0x2594 has exited with code -1073741510 (0xc000013a).
The thread 0x26a0 has exited with code -1073741510 (0xc000013a).
The thread 0x2be4 has exited with code -1073741510 (0xc000013a).
The thread 0x11c has exited with code -1073741510 (0xc000013a).
What should I do now to understand why the program keeps crashing?