2012-12-16 4 views
0

다음 코드를 패턴 인식에 사용했습니다. 그러나 그것은 잘못된 일치 결과를 제공합니다. 제발 내가 잘못한 것을 도와주세요. 이것은 xcode로 작성되었습니다.대상에서 일치하는 템플릿 -c openCV 사용

Mat img_display; 
img.copyTo(img_display); 

/// Create the result matrix 
int result_cols = img.cols - templ.cols + 1; 
int result_rows = img.rows - templ.rows + 1; 

result.create(result_cols, result_rows, CV_32FC1); 

/// Do the Matching and Normalize 
matchTemplate(img, templ, result, 5); 
normalize(result, result, 0, 1, NORM_MINMAX, -1, Mat()); 

/// Localizing the best match with minMaxLoc 
double minVal; double maxVal; Point minLoc; Point maxLoc; 
Point matchLoc; 

minMaxLoc(result, &minVal, &maxVal, &minLoc, &maxLoc, Mat()); 


/// For SQDIFF and SQDIFF_NORMED, the best matches are lower values. For all the other methods, the higher the better 
if(match_method == CV_TM_SQDIFF || match_method == CV_TM_SQDIFF_NORMED) 
{ 
    matchLoc = minLoc; 
    printf("fsf"); 
} 
else 
{ 
    matchLoc = maxLoc; 
    printf("fsf2"); 
} 

/// Show me what you got 
rectangle(img_display, matchLoc, Point(matchLoc.x + templ.cols , matchLoc.y + templ.rows), Scalar::all(0), 2, 8, 0); 
//rectangle(result, matchLoc, Point(matchLoc.x + templ.cols , matchLoc.y + templ.rows), Scalar::all(0), 2, 8, 0); 

//imshow(image_window, img_display); 
//imshow(result_window, result); 

return img_display; 

미리 감사드립니다. 여기 스크린 샷 enter image description here

를 첨부

enter image description here

+0

** 잘못된 검색 결과 ** 란 무엇입니까? – ArtemStorozhuk

+0

안녕하세요. Astor에서 수정 된 질문을 확인하십시오. 감사합니다. – sri

+0

템플릿은 무엇입니까? 또한, 어떻게이 접근 방식으로 잘못된 결과를 얻지 못할 것이라고 기대하십니까? 함수가 'matchTemplate'라는 이름으로되어있어서 마술처럼 항상 맞습니까? 무슨 일이 일어나고 있는지 모른 채 준비된 패키지를 사용하면 슬프다. – mmgp

답변

1

당신은 교체해야 result.create (result_cols, result_rows, CV_32FC1); with result.create (result_rows, result_cols, CV_32FC1);