• opencv--模板匹配



    1
    #include "stdafx.h" 2 #include <windows.h> 3 #include <baseapi.h> 4 #include <opencv2opencv.hpp> 5 6 using namespace cv; 7 using namespace std; 8 #pragma comment(lib,"libtesseract302d.lib") 9 10 int main() 11 { 12 IplImage *src = cvLoadImage("C:\Users\Bite07\Desktop\1.jpg", 0); 13 IplImage *srcResult = cvLoadImage("C:\Users\Bite07\Desktop\1.jpg", 3); //用来显示 14 IplImage *templat = cvLoadImage("C:\Users\Bite07\Desktop\4.jpg", 0); 15 IplImage *result; // 用来存放结果 16 17 if(!src || !templat) 18 { 19 cout << "打开图像失败"<< endl; 20 return 0; 21 } 22 int srcW, srcH, templatW, templatH, resultH, resultW; 23 srcW = src->width; 24 srcH = src->height; 25 templatW = templat->width; 26 templatH = templat->height; 27 if(srcW < templatW || srcH < templatH) 28 { 29 cout <<"模板不能比原图像大" << endl; 30 return 0; 31 } 32 resultW = srcW - templatW + 1; 33 resultH = srcH - templatH + 1; 34 result = cvCreateImage(cvSize(resultW, resultH), 32, 1); 35 36 cvMatchTemplate(src, templat, result, CV_TM_SQDIFF); 37 double minValue, maxValue; 38 CvPoint minLoc, maxLoc; 39 40 cvMinMaxLoc(result, &minValue, &maxValue, &minLoc, &maxLoc); 41 cvRectangle(srcResult, minLoc, cvPoint(minLoc.x + templatW, minLoc.y+ templatH), cvScalar(0,0,255)); 42 43 cvNamedWindow("srcResult", 0); 44 cvNamedWindow("templat", 0); 45 cvShowImage("srcResult", srcResult); 46 cvShowImage("templat", templat); 47 cvWaitKey(0); 48 cvReleaseImage(&result); 49 cvReleaseImage(&templat); 50 cvReleaseImage(&srcResult); 51 cvReleaseImage(&src); 52 return 0; 53 }

    参考至:http://blog.csdn.net/lu597203933/article/details/14548523

  • 相关阅读:
    【转】基于 Apache 在本地配置多个虚拟主机
    ubuntu linux下各种格式软件包的安装卸载
    钩子
    静态方法中不能使用 $this
    Redis Sentinel机制与用法说明【转】
    CI 分页类的使用
    MySQL压力测试
    简单配置.htaccess就可以实现的10个功能
    bzoj 3529 数表
    poj2773 Happy 2006
  • 原文地址:https://www.cnblogs.com/bent/p/4152757.html
Copyright © 2020-2023  润新知