저장소
템플릿 매칭 본문
#include <opencv/cv.h>
#include <opencv/highgui.h>
void Show(char *str, IplImage *img)
{
cvNamedWindow( str, 1);
cvShowImage( str, img );
}
void main() {
double min, max;
CvPoint left_top;
IplImage *A = cvLoadImage("C:/Users/Administrator/Desktop/pop.png", -1); // pop 먼저 읽고
IplImage *B = cvLoadImage("C:/Users/Administrator/Desktop/pop1.png", -1); // pop1dmf 읽는다.
IplImage* C = cvCreateImage( cvSize( A->width - B->width+1, A->height - B->height+1 ), IPL_DEPTH_32F, 1 ); // 상관계수를 구할 이미지(C)
cvMatchTemplate(A, B, C, CV_TM_CCOEFF_NORMED); // 상관계수를 구하여 C 에 그린다.
cvMinMaxLoc(C, &min, &max, NULL, &left_top); // 상관계수가 최대값을 값는 위치 찾기
cvRectangle(A, left_top, cvPoint(left_top.x + B->width, left_top.y + B->height), CV_RGB(255,0,0)); // 찾은 물체에 사격형을 그린다.
Show("T9-result",A); // 결과 보기
Show("T9-sample",B); // 스테이플러(B) 보기
Show("C",C); // 상관계수 이미지 보기
cvWaitKey(0);
// 모든 이미지 릴리즈
cvReleaseImage(&A);
cvReleaseImage(&B);
cvReleaseImage(&C);
// 모든 윈도우 제거
cvDestroyAllWindows();
}
'OpenCV' 카테고리의 다른 글
영상반전 (0) | 2016.04.10 |
---|---|
이미지 띄우기 (0) | 2016.04.09 |
edge detection(canny) (0) | 2016.04.09 |
edge detection(sobel) (0) | 2016.04.09 |
이미지 회전 (0) | 2016.04.08 |