乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      【圖像算法】模板匹配

       熊貓發(fā)作 2015-08-16

      圖像算法:模板匹配

      SkySeraph Mar 29th 2011  HQU

      Email:zgzhaobo@    QQ:452728574

      Latest Modified Date:Mar 29th 2011 HQU

      一 工具:VC6.0+OpenCV1.0

           語言:CPP

      二 原理

         1 函數(shù) cvMatchTemplate

          //功能:比較模板和重疊的圖像區(qū)域
          //原型:void cvMatchTemplate(
           const CvArr* image,   //欲搜索的圖像。它應(yīng)該是單通道、8-比特或32-比特 浮點(diǎn)數(shù)圖像
           const CvArr* templ,  //搜索模板,不能大于輸入圖像,且與輸入圖像具有一樣的數(shù)據(jù)類型
           CvArr* result,     //比較結(jié)果的映射圖像。單通道、32-比特浮點(diǎn)數(shù).
                           若圖像是W×H而templ是w×h,則result一定是(W-w+1)×(H-h+1)
           int method      //CV_TM_SQDIFF、CV_TM_SQDIFF_NORMED、CV_TM_CCORR、
                          CV_TM_CCORR_NORMED、CV_TM_CCOEFF、CV_TM_CCOEFF_NORMED
           );
          //說明

        關(guān)于參數(shù)result[2]:
             含義:依次計算模板與待測圖片的重疊區(qū)域的相似度,result圖像中的每一個點(diǎn)的值代表了一次相似度比較結(jié)果
             尺寸:橫向比較W-w+1次,縱向比較H-h+1次
             獲取最佳匹配區(qū)域:
                使用函數(shù)cvMinMaxLoc提取最大值(相似度最高)以及最大值的位置
                rect=cvRect(max_loc.x,max_loc.y,tmp->width,tmp->height);

            rect表示的矩形區(qū)域即是最佳的匹配區(qū)域
        關(guān)于參數(shù) method:

            CV_TM_SQDIFF 平方差匹配法:該方法采用平方差來進(jìn)行匹配;最好的匹配值為0;匹配越差,匹配值越大。
            CV_TM_CCORR 相關(guān)匹配法:該方法采用乘法操作;數(shù)值越大表明匹配程度越好。
            CV_TM_CCOEFF 相關(guān)系數(shù)匹配法:1表示完美的匹配;-1表示最差的匹配。
            CV_TM_SQDIFF_NORMED 歸一化平方差匹配法
            CV_TM_CCORR_NORMED 歸一化相關(guān)匹配法
            CV_TM_CCOEFF_NORMED 歸一化相關(guān)系數(shù)匹配法
      2  函數(shù):cvMinMaxLoc

          /*-----------------cvMinMaxLoc------------------//
          //功能:查找數(shù)組和子數(shù)組的全局最小值和最大值
          //函數(shù):
          void cvMinMaxLoc(
           const CvArr* arr, //輸入數(shù)組, 單通道或者設(shè)置了 COI 的多通道
           double* min_val, //指向返回的最小值的指針
           double* max_val,//指向返回的最大值的指針
           CvPoint* min_loc=NULL, //指向返回的最小值的位置指針
           CvPoint* max_loc=NULL, //指向返回的最大值的位置指針
           const CvArr* mask=NULL//選擇一個子數(shù)組的操作掩模
           );
          //----------------------------------------------*/

      三 源碼(完整)

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
      47
      48
      49
      50
      51
      52
      53
      54
      55
      56
      57
      58
      59
      60
      61
      62
      63
      64
      65
      66
      67
      68
      69
      70
      71
      72
      73
      74
      75
      76
      77
      78
      79
      80
      81
      82
      83
      84
      85
      86
      87
      88
      89
      90
      91
      92
      93
      94
      95
      96
      97
      98
      99
      /*===============================================//
      功能:Template Matching with OpenCV
      時間:3/22/2011 SkySeraph HQU
      //===============================================*/
      #include "iostream"
      using namespace std;
      #include "cv.h"
      #include "highgui.h"
      #include "math.h"
      #pragma comment(lib,"highgui.lib")
      #pragma comment(lib,"cv.lib")
      #pragma comment(lib,"cvaux.lib")
      #pragma comment(lib,"cxcore.lib")
      const char* filename1 = "D:\\My Documents\\My Pictures\\Images\\歸一化.bmp";
      const char* filename2 = "D:\\My Documents\\My Pictures\\Images\\歸一化模板.bmp";
      /*=============================================*/
      int main( int argc, char** argv )
      {
          IplImage    *img;
          IplImage    *tpl;
          IplImage    *res;
          CvPoint     minloc, maxloc;
          double      minval, maxval;
          int         img_width, img_height;
          int         tpl_width, tpl_height;
          int         res_width, res_height;
          img = cvLoadImage( filename1, CV_LOAD_IMAGE_COLOR );
          tpl = cvLoadImage( filename2, CV_LOAD_IMAGE_COLOR );
          if( tpl == 0 )
          {
              fprintf( stderr, "Cannot load file %s!\n", argv[2] );
              return 1;
          }
          cvNamedWindow( "src", CV_WINDOW_AUTOSIZE );
          cvShowImage( "src", img );
          cvNamedWindow( "template", CV_WINDOW_AUTOSIZE );
          cvShowImage( "template", tpl );
          /* get image's properties */
          img_width  = img->width;
          img_height = img->height;
          tpl_width  = tpl->width;
          tpl_height = tpl->height;
          res_width  = img_width - tpl_width + 1;
          res_height = img_height - tpl_height + 1;
          /* create new image for template matching computation */
          res = cvCreateImage( cvSize( res_width, res_height ), IPL_DEPTH_32F, 1 );
          /* choose template matching method to be used */
           cvMatchTemplate( img, tpl, res, CV_TM_CCORR_NORMED );
          /*cvMatchTemplate( img, tpl, res, CV_TM_SQDIFF_NORMED );
          cvMatchTemplate( img, tpl, res, CV_TM_CCORR );
          cvMatchTemplate( img, tpl, res, CV_TM_SQDIFF );
          cvMatchTemplate( img, tpl, res, CV_TM_CCOEFF );
          cvMatchTemplate( img, tpl, res, CV_TM_CCOEFF_NORMED );*/
          cvNamedWindow( "res", CV_WINDOW_AUTOSIZE );
          cvShowImage( "res", res );
          cvMinMaxLoc( res, &minval, &maxval, &minloc, &maxloc, 0 );
          /* draw red rectangle */
          /*cvRectangle( img,
                       cvPoint( minloc.x, minloc.y ),
                       cvPoint( minloc.x + tpl_width, minloc.y + tpl_height ),
                       cvScalar( 0, 0, 255, 0 ), 1, 0, 0 );*/
          CvPoint pt1;
          CvPoint pt2;
          CvRect rect;
          rect=cvRect(maxloc.x,maxloc.y,tpl->width,tpl->height);//最佳的匹配區(qū)域
          pt1=cvPoint(rect.x,rect.y);
          pt2=cvPoint(rect.x+rect.width,rect.y+rect.height);
          cvRectangle( img,pt1, pt2, cvScalar(0,0,255),1, 8, 0 );
          /* display images */
          cvNamedWindow( "reference", CV_WINDOW_AUTOSIZE );
          cvShowImage( "reference", img );
          /* wait until user press a key to exit */
          cvWaitKey( 0 );
          /* free memory */
          cvDestroyWindow( "reference" );
          cvDestroyWindow( "template" );
          cvReleaseImage( &img );
          cvReleaseImage( &tpl );
          cvReleaseImage( &res );
          return 0;
      }

      四 效果

      五 參考:

      [1]    http:///template-matching-in-opencv-with-example.html
      [2] http://www./Article/show.asp?id=135

      六 其它
      平臺: http://www.cnblogs.com/skyseraph/archive/2011/03/29/1998492.html
               http://www.cnblogs.com/skyseraph/archive/2011/03/29/1998536.html

      Author:         SKySeraph

      Email/GTalk: zgzhaobo@    QQ:452728574

      From:         http://www.cnblogs.com/skyseraph/

      本文版權(quán)歸作者和博客園共有,歡迎轉(zhuǎn)載,但未經(jīng)作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,請尊重作者的勞動成果。

        本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多