opencv:轮廓匹配


#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:轮廓匹配的更多相关文章
- 【OpenCV学习笔记】三十、轮廓特征属性及应用(七)—位置关系及轮廓匹配
http://blog.csdn.net/abc8730866/article/details/69219992 轮廓特征属性及应用(七)—位置关系及轮廓匹配 1.计算点与轮廓的距离及位置关系——po ...
- OpenCV应用(3) 简单轮廓匹配的小例子
具体应用 https://blog.csdn.net/kyjl888/article/details/85060883 OpenCV中提供了几个与轮廓相关的函数: findContours():从二值 ...
- OpenCV 轮廓基本特征
http://blog.csdn.net/tiemaxiaosu/article/details/51360499 OpenCV 轮廓基本特征 2016-05-10 10:26 556人阅读 评论( ...
- EmguCV 轮廓匹配
一.相关类 MCvMoments inv_sqrt_m00 m00!=0?1/sqrt(m00):0 m00 spatial moments m01, m02, m03, m10, m11 m12, ...
- opencv轮廓处理函数详细
ApproxChains 用多边形曲线逼近 Freeman 链 CvSeq* cvApproxChains( CvSeq* src_seq, CvMemStorage* storage, int me ...
- OpenCV轮廓vectorvector
OpenCV轮廓vectorvector,vector,vector,vector https://blog.csdn.net/Ahuuua/article/details/80593388 轮廓 ...
- Atitit opencv模板匹配attilax总结
Atitit opencv模板匹配attilax总结 找一幅图像的匹配的模板,可以在一段视频里寻找出我们感兴趣的东西,比如条形码的识别就可能需要这样类似的一个工作提取出条形码区域(当然这样的方法并不鲁 ...
- Atitit opencv 模板匹配
Atitit opencv 模板匹配 1.1. 图片1 1.2. Atitit opencv 模板匹配 6中匹配算法貌似效果区别不大1 1.3. 对模板缩放的影响 一般的缩放可以,太大了就歇菜了.. ...
- opencv学习之路(28)、轮廓查找与绘制(七)——位置关系及轮廓匹配
一.点与轮廓的距离及位置关系 #include "opencv2/opencv.hpp" #include <iostream> using namespace std ...
- Opencv Match Template(轮廓匹配)
#include <iostream>#include <opencv2/opencv.hpp> using namespace std;using namespace cv; ...
随机推荐
- 1、腾讯云搭建Hadoop3集群
1主机名和IP配置 1.1主机名 1.首先使用root用户名和root密码分别登录三台服务器 2.分别在三台虚拟机上执行命令: hostnamectl set-hostname node1 hostn ...
- http协议的POST传数据
PostRequest使用StreamWriter对象写入请求流,不需要使用HttpUtility.UrlEncode显示转码,而下面的需要显示转码,还需要将参数转为字节码 蛋疼…………. publi ...
- Windows新建域时 administrator账户密码不符合要求解决办法~!
解决方法 在cmd 命令行中 输入 net user administrator /passwordreq:yes
- Linux运维--14.Kolla部署OpenStack使用external MariaDB Galera Cluster
使用haproxy+keepalived实现Mariadb负载均衡 controller2: 10.100.2.52 haproxy+keepalived controller3: 10.100.2. ...
- R语言函数话学习笔记5
使用Tidyverse完成函数化编程 (参考了家翔学长的笔记) 1.magrittr包的使用 里面有很多的管道函数,,可以减少代码开发时间,提高代码可读性和维护性 1.1 四种pipeline 1.1 ...
- pytorch之max()函数
pytorch之max()函数 待办 返回对应给定中最大值的索引,方便进行和target结果的索引进行比较 索引方式见下 https://blog.csdn.net/liuweiyuxiang/art ...
- Linux oracle安装 内核参数讲解
在安装Oracle的时候需要调整linux的内核参数,但是各参数代表什么含义呢,下面做详细解析. Linux安装文档中给出的最小值: fs.aio-max-nr = 1048576 fs.file-m ...
- Motif
Motif discovery is in loose terms the problem of finding interesting patterns in sequences. motif: i ...
- php curl 发起get和post网络请求
curl介绍 curl是一个开源的网络链接库,支持http, https, ftp, gopher, telnet, dict, file, and ldap 协议.之前均益介绍了python版本的p ...
- Git 添加远程github仓库的时候提示错误:fatal: remote origin already exists.
1.先删除远程 Git 仓库 $ git remote rm origin 2.再添加远程 Git 仓库 $ git remote add origin git@github.com:wsydxian ...