opencv 模板匹配, 已解决模板过大程序不工作的bug
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <math.h> #ifdef _DEBUG
#pragma comment ( lib,"opencv_highgui244d.lib" )
#pragma comment ( lib,"opencv_core244d.lib" )
#pragma comment ( lib,"opencv_imgproc244d.lib" )
#else
#pragma comment ( lib,"opencv_highgui244.lib" )
#pragma comment ( lib,"opencv_core244.lib" )
#pragma comment ( lib,"opencv_imgproc244.lib" )
#endif using namespace std;
using namespace cv; //get the index of the min value
int app(vector<double> minV)
{
int t=0;
for (int i = 1; i < minV.size();i++)
{
if (minV[i] < minV[t]) t = i;
} return t;
} int main( )
{
Mat img = imread("src1.jpg"); //原图像
Mat temp = imread("template1.png"); //模板
Mat result; vector<double> minV;
vector<Point> minL; vector<Mat> down_temp;
down_temp.push_back(temp); //匹配4次,每次模板缩小1/1.3
for (int i=0;i<4;i++)
{
long begin = GetTickCount();
Mat temp1; cout<<down_temp[i].cols<<endl;
cout<<down_temp[i].rows<<endl; int result_cols = img.cols - down_temp[i].cols + 1;
int result_rows = img.rows - down_temp[i].rows + 1;
result.create( result_cols, result_rows, CV_32FC1 );
matchTemplate( img, down_temp[i], result, CV_TM_SQDIFF ); double minVal;
double maxVal;
Point minLoc;
Point maxLoc;
Point matchLoc; minMaxLoc( result, &minVal, &maxVal, &minLoc, &maxLoc); minVal=minVal/(down_temp[i].cols*down_temp[i].rows);
cout<<minVal<<endl;
minV.push_back(minVal);
minL.push_back(minLoc);
resize( down_temp[i], temp1, Size( down_temp[i].cols/1.3, down_temp[i].rows/1.3) );
down_temp.push_back(temp1); cout<< " calculate time : " << GetTickCount()-begin<<endl;
} int location; location = app(minV); rectangle( img, minL[location], Point( minL[location].x + down_temp[location].cols , minL[location].y + down_temp[location].rows ), Scalar::all(0), 2, 8, 0 ); imshow("结果",img); waitKey(); return 0;
}
opencv 模板匹配, 已解决模板过大程序不工作的bug的更多相关文章
- 使用 c++ 模板显示实例化解决模板函数声明与实现分离的问题
问题背景 开始正文之前,做一些背景铺垫,方便读者了解我的工程需求.我的项目是一个客户端消息分发中心,在连接上消息后台后,后台会不定时的给我推送一些消息,我再将它们转发给本机的其它桌面产品去做显示.后台 ...
- thinkcmf5更新模板代码分析,解决模板配置json出错导致数据库保存的配置项内容丢失问题
private function updateThemeFiles($theme, $suffix = 'html') { $dir = 'themes/' . $theme; $themeDir = ...
- Atitit opencv模板匹配attilax总结
Atitit opencv模板匹配attilax总结 找一幅图像的匹配的模板,可以在一段视频里寻找出我们感兴趣的东西,比如条形码的识别就可能需要这样类似的一个工作提取出条形码区域(当然这样的方法并不鲁 ...
- opencv::模板匹配(Template Match)
模板匹配介绍 模板匹配就是在整个图像区域发现与给定子图像匹配的小块区域. 所以模板匹配首先需要一个模板图像T(给定的子图像) 另外需要一个待检测的图像-源图像S 工作方法,在带检测图像上,从左到右,从 ...
- OpenCV-Python:模板匹配
啥叫模板匹配 模板匹配就是在大图中找小图,也就说在一幅图像中寻找另一幅模板图像的位置: OpenCV使用 cv2.matchTemplate() 实现模板匹配. import cv2 import n ...
- 基于HALCON的模板匹配方法总结
注:很抱歉,忘记从转载链接了,作者莫怪.... 基于HALCON的模板匹配方法总结 很早就想总结一下前段时间学习HALCON的心得,但由于其他的事情总是抽不出时间.去年有过一段时间的集中学习,做了许多 ...
- 转载:基于HALCON的模板匹配方法总结
转载链接: http://blog.csdn.net/b108074013/article/details/37657801 很早就想总结一下前段时间学习HALCON的心得,但由于其他的事情总 ...
- 基于HALCON的模板匹配方法总结 (转)
很早就想总结一下前段时间学习HALCON的心得,但由于其他的事情总是抽不出时间.去年有过一段时间的集中学习,做了许多的练习和实验,并对基于HDevelop的形状匹配算法的参数优化进行了研究,写了一篇& ...
- halcon 模板匹配 -- 转化 vector_angle_to_rigid
********************************模板匹配 ********************create_shape_model创建模板,这个函数有许多参数,其中金字塔的级数由N ...
随机推荐
- Video Captioning 综述
1.Unsupervised learning of video representations using LSTMs 方法:从先前的帧编码预测未来帧序列 相似于Sequence to sequen ...
- 【Makefile】Makefile中的常用函数简介
1. subst函数 格式:$(subst <from>, <to>, <text>)功能:把字串<text>中的<from>字符串替换成& ...
- LC 275. H-Index II
Given an array of citations sorted in ascending order (each citation is a non-negative integer) of a ...
- CentOS7出现Unit iptables.service could not be found
CentOS7默认的防火墙不是iptables,而是firewalle. 出现此情况可能是iptables防火墙未安装. #停止firewalld服务 systemctl stop firewalld ...
- Python3 循环_break和continue语句及循环中的else子句
break和continue语句及循环中的else子句break语句可以跳出for和while的循环体.如果你从for或while循环中终止,任何对应的循环else块将不执行. continue语句被 ...
- Java之Apache Tomcat教程[归档]
前言 笔记归档类博文. 本博文地址:Java之Apache Tomcat教程[归档] 未经同意或授权便复制粘贴全文原文!!!!盗文实在可耻!!!贴一个臭不要脸的:易学教程↓↓↓ Step1:安装JDK ...
- vue cli创建typescript项目
使用最新的Vue CLI @vue/cli创建typescript项目,使用vue -V查看当前的vue cli版本 安装命令 npm install -g @vue-cli 创建项目 vue cre ...
- Gitlab-Runner基础教程
一.Intro jenkins和runner,作为主流自动化运维工具来说,两者的大思路其实是一样的,就是将我们提交到代码仓库的代码拉到jenkins或者runner运行的机器里,然后执行一系列的命令( ...
- Linux服务知识点总结
一.firewalld防火墙 1.firewalld简述 firewalld:防火墙,其实就是一个隔离工具:工作于主机或者网络的边缘.对于进出本主机或者网络的报文根据事先定义好的网络规则做匹配检测,对 ...
- 【VS开发】学习VS2010 ------ 多种类型的视图集合CTabView
多种类型的视图集合CTabView 首先利用AppWizard建立工程,然后将视类的基类更改为CTabView,并将所有的CView更改为CTabView. 依次插入以CSrollView.CList ...