#include <opencv2/opencv.hpp>
#include <iostream> using namespace cv;
using namespace std;
RNG rng(12345); void contour_info(Mat &image, vector<vector<Point>> &contours); int main(int argc, char** argv)
{
Mat src1 = imread("f:/images/qq/20200215213837.png"); // 查找的图像
Mat src2 = imread("f:/images/qq/one_mi.png"); //模板
//Mat src = imread("f:/images/qq/yezi.png");
if (src1.empty() || src2.empty())
{
printf("Could not find the image!\n");
return -1;
} //namedWindow("input", WINDOW_AUTOSIZE);
imshow("input1", src1);
imshow("input2", src2); vector<vector<Point>> contours1;
vector<vector<Point>> contours2;
contour_info(src1, contours1);
contour_info(src2, contours2); Moments mm2 = moments(contours2[0]);
Mat hu2;
HuMoments(mm2, hu2); for (size_t t = 0; t < contours1.size(); t++) {
Moments mm = moments(contours1[t]);
// 计算每个轮廓的中心位置
double cx = mm.m10 / mm.m00;
double cy = mm.m01 / mm.m00;
circle(src1, Point(cx, cy), 3, Scalar(0, 255, 0), 2, 8, 0);
Mat hu;
HuMoments(mm, hu);
double dist = matchShapes(hu, hu2, CONTOURS_MATCH_I1, 0);
if (dist < 1.0) {
drawContours(src1, contours1, t, Scalar(0, 0, 255), 2, 8);
}
}
imshow("match contours demo", src1); waitKey(0);
destroyAllWindows(); return 0;
} void contour_info(Mat& image, vector<vector<Point>>& contours) {
Mat dst;
GaussianBlur(image, dst, Size(3, 3), 0);
Mat gray, binary;
cvtColor(dst, gray, COLOR_BGR2GRAY);
threshold(gray, binary, 0, 255, THRESH_BINARY | THRESH_OTSU);
vector<Vec4i> hierarchy;
findContours(binary, contours, hierarchy, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE, Point());
}

opencv:轮廓匹配的更多相关文章

  1. 【OpenCV学习笔记】三十、轮廓特征属性及应用(七)—位置关系及轮廓匹配

    http://blog.csdn.net/abc8730866/article/details/69219992 轮廓特征属性及应用(七)—位置关系及轮廓匹配 1.计算点与轮廓的距离及位置关系——po ...

  2. OpenCV应用(3) 简单轮廓匹配的小例子

    具体应用 https://blog.csdn.net/kyjl888/article/details/85060883 OpenCV中提供了几个与轮廓相关的函数: findContours():从二值 ...

  3. OpenCV 轮廓基本特征

     http://blog.csdn.net/tiemaxiaosu/article/details/51360499 OpenCV 轮廓基本特征 2016-05-10 10:26 556人阅读 评论( ...

  4. EmguCV 轮廓匹配

    一.相关类 MCvMoments inv_sqrt_m00 m00!=0?1/sqrt(m00):0 m00  spatial moments m01, m02, m03, m10, m11 m12, ...

  5. opencv轮廓处理函数详细

    ApproxChains 用多边形曲线逼近 Freeman 链 CvSeq* cvApproxChains( CvSeq* src_seq, CvMemStorage* storage, int me ...

  6. OpenCV轮廓vectorvector

    OpenCV轮廓vectorvector,vector,vector,vector https://blog.csdn.net/Ahuuua/article/details/80593388   轮廓 ...

  7. Atitit opencv模板匹配attilax总结

    Atitit opencv模板匹配attilax总结 找一幅图像的匹配的模板,可以在一段视频里寻找出我们感兴趣的东西,比如条形码的识别就可能需要这样类似的一个工作提取出条形码区域(当然这样的方法并不鲁 ...

  8. Atitit opencv 模板匹配

    Atitit opencv 模板匹配 1.1. 图片1 1.2. Atitit opencv 模板匹配  6中匹配算法貌似效果区别不大1 1.3. 对模板缩放的影响 一般的缩放可以,太大了就歇菜了.. ...

  9. opencv学习之路(28)、轮廓查找与绘制(七)——位置关系及轮廓匹配

    一.点与轮廓的距离及位置关系 #include "opencv2/opencv.hpp" #include <iostream> using namespace std ...

  10. Opencv Match Template(轮廓匹配)

    #include <iostream>#include <opencv2/opencv.hpp> using namespace std;using namespace cv; ...

随机推荐

  1. MongoDB批量更新和批量插入的方式

    最近,在调试代码中发现向MongoDB插入或者更新文档记录时若是多条的话都是采用for循环操作的,这样的处理方式会造成数据操作耗时,不符合批量处理的原则:对此,个人整理了一下有关MongoDB的批量更 ...

  2. SendMessage模拟按键所需的虚拟键码

    Virtual-Key Codes The following table shows the symbolic constant names, hexadecimal values, and mou ...

  3. python3.6安装lxml库

    好像是在python3.5之后,安装了lxml也无法使用etree 为了就解决这个问题使用如下方法: 1.下载lxml的wheel文件,下载地址:https://www.lfd.uci.edu/~go ...

  4. 机器学习作业(八)异常检测与推荐系统——Matlab实现

    题目下载[传送门] 第1题 简述:对于一组网络数据进行异常检测. 第1步:读取数据文件,使用高斯分布计算 μ 和 σ²: % The following command loads the datas ...

  5. MyBatis的手动映射与模糊查询

    一.手动映射 当实体类属性与数据库字段名不同时,无法自动映射,导致查询出空值,这时候可以使用手动映射 在select节点添加resultMap属性与resultMap节点建立关系

  6. PP: A dual-stage attention-based recurrent neural network for time series prediction

    Problem: time series prediction The nonlinear autoregressive exogenous model: The Nonlinear autoregr ...

  7. jqgrid中分页和搜索,jqgrid loadonce:true后trigger("reloadGrid")无效

      第一次接触jqgrid,发现项目中好多地方都用到.   jqgrid是典型的B/S架构(浏览器/服务器模式),服务器端只需提供数据管理,浏览器只需负责数据显示.   jqGrid是用ajax实现对 ...

  8. 自定义Nginx返回页面

    1.403返回页面 #user nobody; worker_processes ; #error_log logs/error.log; #error_log logs/error.log noti ...

  9. 全文检索工具elasticsearch和kibana安装

    一.安装elasticsearch 1.拷贝elasticsearch-5.6.4.rpm到/opt目录下「cenos7」 systemctl list-unit-files|grep elastic ...

  10. SQL操作DBF

    --从SQL Server查询器预览dBase 文件中数据select * from openrowset('MICROSOFT.ACE.OLEDB.12.0','dBase 5.0;database ...