嗨,我试图调试一个C++/C开发人员的代码,他给我们写了一个动态链接库,我们在一个adobe本地扩展中使用,这个扩展基本上是用网络摄像头的网格拍摄照片,在做了一些人脸检测之后,应该是裁剪图像并将它们写到磁盘上。
但应用程序总是挂起,并最终在下面这一行崩溃:
smallFrame = image(Rect(x, y, CROPPING_WIDTH, CROPPING_HEIGHT));我已经通过抛出try/catch来将它缩小到这一行,它抛出的异常并不是很有帮助,它只是说?n作为异常。
如下所示:
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;
}下面是整个方法:
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;
}发布于 2013-08-12 22:30:35
smallFrame = image(Rect(x, y, CROPPING_WIDTH, CROPPING_HEIGHT));*固定的CROPPING_WIDTH或高度不起作用。您必须检查,如果您的Rect没有在图像之外的部分结束,即如果x+CROPPING_WIDTH
发布于 2013-08-12 23:31:43
berak向您解释了错误的可能原因,但您无法调试的原因是您正在使用:
wsprintf (str, L"Exception Occured during Face Found : %s", ex.what());在Visual Studio环境中,使用ex.what()返回一个const char*。不幸的是,%s的行为依赖于平台,在这种情况下,它需要一个宽字符串(因此,%s对于wsprintf是宽字符串,对于sprintf是字节字符串)。在Unix中,您会有正确的行为。在Visual Studio中,您必须使用%S。
检查这个:printf, wprintf, %s, %S, %ls, char* and wchar*: Errors not announced by a compiler warning?,特别是this。
https://stackoverflow.com/questions/18188872
复制相似问题