模板匹配
程序员文章站
2022-04-01 09:29:33
...
#include<opencv2/opencv.hpp>
#include<iostream>
#include<math.h>
using namespace std;
using namespace cv;
int main()
{
Mat src1 = imread("D:\\test1.bmp", IMREAD_GRAYSCALE);
Mat src2 = imread("D:\\test2.bmp", IMREAD_GRAYSCALE);
if (src1.empty()|| src2.empty())
{
cout << " image read error" << endl;
return -1;
}
//去除原图黑边得到64*64图像
Mat img1 = src1(Range(130, 194), Range(320, 384));
Mat img2 = src2(Range(130, 194), Range(320, 384));
int rows1 = img1.rows;
int cols1 = img1.cols;
int rows2 = img2.rows;
int cols2 = img2.cols;
//取第一幅图片的中间区域templ作为模板,大小为41*41
Mat templ = img1(Range(rows1 / 2 - 20, rows1 / 2 + 21), Range(cols1 / 2 - 20, cols1 / 2 + 21));
int result_cols = img2.cols - templ.cols + 1;
int result_rows = img2.rows - templ.rows + 1;
Mat result(result_rows, result_cols, CV_32FC1); //result 输出结果,必须是单通道32位浮点数
//进行模板匹配
matchTemplate(img2, templ, result, 3);//result 输出结果,必须是单通道32位浮点数
Point minLoc;
Point maxLoc;
double min, max;
minMaxLoc(result, &min, &max, &minLoc, &maxLoc);
cout << "max="<<max << endl;
cout << "maxLoc="<<maxLoc << endl;
system("pause");
return 0;
}
上一篇: 大坑,有什么办法可以出来
下一篇: 一道小学奥数题的Java编程实现
推荐阅读
-
微信小程序模板消息限制实现无限制主动推送的示例代码
-
ae中怎么匹配C4D完成线性工作流程?
-
Js 利用正则表达式和replace函数获取string中所有被匹配到的文本(推荐)
-
koa2使用ejs和nunjucks作为模板引擎的使用
-
自定义Adapter并通过布局泵LayoutInflater抓取layout模板编辑每一个item实现思路
-
企业产品推广策划书怎么写?5个模块具体方法模板全面提升产品竞争力
-
php网页编程软件(php和mysql网站模板)
-
js正则匹配字符串中的数字(js正则匹配字符串中的数字讲解)
-
Java实现的模糊匹配某文件夹下的文件并删除功能示例
-
vue-cli3 项目优化之通过 node 自动生成组件模板 generate View、Component