TM.cpp
上传用户:cfkj28
上传日期:2022-07-27
资源大小:1k
文件大小:2k
- #include <stdio.h>
- #include <cv.h>
- #include <highgui.h>
- #include <math.h>
- int main()
- {
- IplImage *src, *templ, *ftmp[6]; // ftmp will hold results
- int i;
- // Read in the source image to be searched
- src = cvLoadImage("MGC.jpg");
- if(src== 0) {
- printf("Error on reading template %sn","temp");
- return(-1);
- }
- // Read in the template to be used for matching:
- templ = cvLoadImage("template.jpg");
- if(templ== 0) {
- printf("Error on reading template %sn","temp");
- return(-1);
- }
- // Allocate Output Images:
- int iwidth = src->width - templ->width + 1;
- int iheight = src->height - templ->height + 1;
- for(i = 0; i < 6; ++i){
- ftmp[i]= cvCreateImage( cvSize( iwidth, iheight ), 32, 1 );
- }
- // Do the matching of the template with the image
- for( i = 0; i < 6; ++i ){
- cvMatchTemplate( src, templ, ftmp[i], i );
- cvNormalize( ftmp[i], ftmp[i], 1, 0, CV_MINMAX );
- }
- // DISPLAY
- cvNamedWindow( "Template", 0 );
- cvShowImage( "Template", templ );
- cvNamedWindow( "Image", 0 );
- cvShowImage( "Image", src );
- cvNamedWindow( "SQDIFF", 0 );
- cvShowImage( "SQDIFF", ftmp[0] );
- cvNamedWindow( "SQDIFF_NORMED", 0 );
- cvShowImage( "SQDIFF_NORMED", ftmp[1] );
- cvNamedWindow( "CCORR", 0 );
- cvShowImage( "CCORR", ftmp[2] );
- cvNamedWindow( "CCORR_NORMED", 0 );
- cvShowImage( "CCORR_NORMED", ftmp[3] );
- cvNamedWindow( "COEFF", 0 );
- cvShowImage( "COEFF", ftmp[4] );
- cvNamedWindow( "COEFF_NORMED", 0 );
- cvShowImage( "COEFF_NORMED", ftmp[5] );
- cvWaitKey(0);
- return 0;
- }