Hi am trying to debug a C++/C developers code, He wrote us a dll that we are using in an adobe native extension that basically takes pictures with a grid of web cams and after doing some face detection is suppose to crop the images and write them to disc.
But the app always hangs and eventually crashes on this line:
smallFrame = image(Rect(x, y, CROPPING_WIDTH, CROPPING_HEIGHT));
i have narrowed it down to this line by throwing a try/catch around it and the exception it spits out is not very helpful, it just says ???????n as the exception.
like so:
try
{
smallFrame = image(Rect(x, y, CROPPING_WIDTH, CROPPING_HEIGHT));
}
catch(exception ex)
{
wsprintf (str, L"Exception Occured during Face Found : %s", ex.what());
WriteLogFile(str);
smallFrame = frame;
}
here is the whole method:
Mat cropFaceFrame( Mat frame)
{
std::vector<Rect> faces;
Mat frame_gray, smallFrame;
int height = 0;
unsigned index, i;
cvtColor( frame, frame_gray, CV_BGR2GRAY );
equalizeHist( frame_gray, frame_gray );
face_cascade.detectMultiScale( frame_gray, faces, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(60, 60));
index = faces.size();
wsprintf (str, L
for (i = 0; i < faces.size(); i++ )
{
if (height < faces[i].height)
{
height = faces[i].height;
index = i;
}
}
Mat image(frame);
int maxRight, maxDown;
maxRight = IMAGE_WIDTH-CROPPING_WIDTH -1;
// right margin
maxDown = IMAGE_HEIGHT-CROPPING_HEIGHT-1;
// down margin
if (index == faces.size())
{
// crop the center part if no face found
try
{
smallFrame = image(Rect(maxRight/2, maxDown/2, CROPPING_WIDTH, CROPPING_HEIGHT));
}
catch(exception ex)
{
smallFrame = frame;
}
}
else
{
int x, y;
x = faces[index].x - (CROPPING_WIDTH-faces[index].width)/2;
if (x < 0) x = 0;
else if (x > maxRight) x = maxRight;
y = faces[index].y - (CROPPING_HEIGHT-faces[index].height)/3;
if (y < 0) y = 0;
else if (y > maxDown) y = maxDown;
try
{
smallFrame = image(Rect(x, y, CROPPING_WIDTH, CROPPING_HEIGHT));
}
catch(exception ex)
{
wsprintf (str, L
"Exception Occured during no Face Found : %s", ex.what());
WriteLogFile(str);
smallFrame = frame;
}
}
return smallFrame;
}