코코야이야기
[c++] OpenCV 템플릿매칭3, ROI(관심영역)설정 본문
소스코드
//사진 템플릿매칭부분에 동영상 띄우기, ROI(관심영역) 설정
#include <cv.h>
#include <highgui.h>
#include <iostream>
using namespace std;
void Show(char *str, IplImage *img)
{
cvNamedWindow( str, 1);
cvShowImage( str, img );
}
void main()
{
double min, max;
CvPoint left_top;
IplImage *src = cvLoadImage("소진_test.jpg", -1);
IplImage *temp = cvLoadImage("testTemp1.jpg", -1);
IplImage *coeff = cvCreateImage( cvSize( src->width - temp->width+1, src->height - temp->height+1 ), IPL_DEPTH_32F, 1 );
cvMatchTemplate(src, temp, coeff, CV_TM_CCOEFF_NORMED);
cvMinMaxLoc(coeff, &min, &max, NULL, &left_top);
Show("Matching Result", src); // 매칭 결과 이미지
Show("Template", temp); // 템플릿 이미지
/////////////////////////////////////////////////////////////////////////////////////
//IplImage* video;
CvCapture * capture = cvCaptureFromAVI("C:/Users/JunAir/Desktop/wildlife.wmv");
IplImage* frame;
IplImage* img;//관심영역 추출용
IplImage* capture_resize;
char c;
while(true){//동영상 프레임 받기
if(cvWaitKey(1)>=0)
break;
if(max>0.9)
{
frame = cvQueryFrame(capture);
if(!frame) break;
//cvShowImage("Tmp",frame);
//////////////////////////
if(frame==NULL)
cvSetCaptureProperty(capture, CV_CAP_PROP_POS_AVI_RATIO , 0);
//관심영역
cvSetImageROI(src,cvRect(left_top.x,left_top.y,temp->width, temp->height));
capture_resize = cvCreateImage(cvSize(temp->width,temp->height),src->depth,3);//depth는 해상도?
cvResize(frame,capture_resize);
cvAddWeighted(src,0.5,capture_resize,0.5,0.0,src);
cvResetImageROI(src);
cvReleaseImage(&capture_resize);
///////////////////////////
}
cvShowImage("ORIGINAL VIDEO",src);
}
cvWaitKey(0);
cvReleaseImage(&src);
cvReleaseImage(&temp);
cvReleaseImage(&coeff);
cvDestroyAllWindows();
}
출력영상
'프로그래밍 > OpenCV' 카테고리의 다른 글
[c++] OpenCV 동영상재생 트랙바 (0) | 2015.09.28 |
---|---|
[c++] OpenCV 템플릿매칭2 (0) | 2015.09.27 |
[c++] OpenCV 카메라영상 (0) | 2015.09.25 |
[c++] OpenCV 템플릿매칭1 (0) | 2015.09.25 |
[c++] OpenCV 특징점검출 (0) | 2015.09.24 |