2013-08-12 3 views
1

안녕하세요, C++/C 개발자 코드를 디버깅하려고합니다. 그는 기본적으로 웹캠 그리드로 사진을 찍는 어도비 네이티브 확장 프로그램에서 dll을 사용하고 있습니다. 얼굴 검색은 이미지를 자르고 디스크에 기록하는 것으로 가정합니다. 그러나 앱이 항상 결국 중단 및OpenCV 및 C로 이미지 자르기

이 라인에 충돌 :

smallFrame = image(Rect(x, y, CROPPING_WIDTH, CROPPING_HEIGHT)); 

내가 주위 시도/캐치를 던져이 라인에 좁혀하고 밖으로 뱉어 예외가 매우 도움이되지 않습니다, 그것은 단지 ??????? n을 예외로 말합니다. 그래서 같은

:

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; 

} 

답변

3
smallFrame = image(Rect(x, y, CROPPING_WIDTH, CROPPING_HEIGHT)); 

고정 CROPPING_WIDTH 또는 높이가하지 않을 것이다 * : 여기

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; 

} 

전체 방법이다. Rect가 이미지 외부에 부분적으로 끝나지 않았다면 확인해야합니다. 즉, x + CROPPING_WIDTH < img.cols-1

0

berak이 오류의 원인을 설명했지만, 디버깅 할 수 없습니다 당신이 사용하는 것입니다 : 비주얼 스튜디오 환경에서

wsprintf (str, L"Exception Occured during Face Found : %s", ex.what()); 

, ex.what (과)는 const char*를 반환. 불행히도 % s 동작은 플랫폼에 따라 다르며,이 경우에는 와이드 문자열이 필요합니다 (따라서 % s는 wsprintf의 경우 넓은 문자열이고 sprintf의 경우 바이트 문자열 임). 유닉스에서는 올바른 행동을 취할 수있다. Visual Studio에서는 % S를 사용해야합니다.

printf, wprintf, %s, %S, %ls, char* and wchar*: Errors not announced by a compiler warning? 및 특히 this을 확인하십시오.