当前位置:网站首页>27. template match
27. template match
2022-06-26 01:36:00 【Nightmare satiety】
#include <opencv2/opencv.hpp>
#include <iostream>
cv::Mat src, temp, dst;
int match_method = cv::TM_SQDIFF;
int max_track = 5;
const char* INPUT_T = "input image";
const char* OUTPUT_T = "result image";
const char* match_t = "template match-demo";
void Match_Demo(int, void*);
int main(int argc, char** argv){
// Pictures to be tested
src = cv::imread("../../source/dog.png");
// Templates
temp = cv::imread("../../source/dog_tmp.png");
if(src.empty() || temp.empty()){
std::cout << "could not load image..." << std::endl;
return -1;
}
cv::namedWindow(INPUT_T, cv::WINDOW_AUTOSIZE);
cv::namedWindow(OUTPUT_T, cv::WINDOW_AUTOSIZE);
cv::namedWindow(match_t, cv::WINDOW_AUTOSIZE);
cv::imshow(INPUT_T, temp);
const char* trackbar_title = "Match Algo Type";
cv::createTrackbar(trackbar_title, OUTPUT_T, &match_method, max_track, Match_Demo);
Match_Demo(0, 0);
cv::waitKey(0);
}
void Match_Demo(int, void*){
int width = src.cols - temp.cols + 1;
int height = src.rows - temp.rows + 1;
cv::Mat result(width, height, CV_32FC1);
cv::matchTemplate(src, temp, result, match_method, cv::Mat());
cv::normalize(result, result, 0, 1, cv::NORM_MINMAX, -1, cv::Mat());
cv::Point minLoc;
cv::Point maxLoc;
double min, max;
src.copyTo(dst);
cv::Point temLoc;
cv::minMaxLoc(result, &min, &max, &minLoc, &maxLoc, cv::Mat());
if(match_method == cv::TM_SQDIFF || match_method == cv::TM_SQDIFF_NORMED){
temLoc = minLoc;
}
else{
temLoc = maxLoc;
}
cv::rectangle(dst, cv::Rect(temLoc.x, temLoc.y, temp.cols, temp.rows), cv::Scalar(0, 0, 255), 2);
cv::rectangle(result, cv::Rect(temLoc.x, temLoc.y, temp.cols, temp.rows), cv::Scalar(0, 0, 255), 2);
imshow(OUTPUT_T, result);
imshow(match_t, dst);
}

边栏推荐
- Development and monitoring of fusion experiment pulse power supply by LabVIEW
- 如何有效地推廣產品
- 填鸭数据即时收集解决方案资源
- 新库上线 | CnOpenDataA股上市公司IPO申报发行文本数据
- Installing MySQL databases in FreeBSD
- 15 `bs对象.节点名称.节点名称.string` 获取嵌套节点内容
- 2021 - 1 - 15 notes de pêche Ctrl + C / V
- Is it safe to open a fund account? Are there any risks?
- Musk vs. jobs, who is the greatest entrepreneur in the 21st century
- [Excel知识技能] Excel数据类型
猜你喜欢

Quickly generate 1~20 natural numbers and easily copy

Multiple interface calls, using promise all、Promise. Race and promise any
![[flower carving experience] 11 start esp32c3](/img/ff/d7c266893ef4ef70c6536085927e0e.jpg)
[flower carving experience] 11 start esp32c3

15 `bs object Node name Node name String` get nested node content

Computer network knowledge summary (interview)

ETCD数据库源码分析——集群通信初始化

LabVIEW开发监控聚变实验脉冲电源

《网络是怎么样连接的》读书笔记 - 集线器、路由器和路由器(三)

Shengxin weekly issue 33

Design and process analysis of anti backflow circuit for MOS transistor
随机推荐
Xinku online | cnopendata text data of IPO declaration and issuance of A-share listed companies
2022 Anhui province safety officer C certificate examination practice questions simulated examination platform operation
通过电脑获取WIFI密码(只能连接过的WiFi)
Flex & Bison 开始
Oracle database complete uninstallation steps (no screenshot)
Nacos registry
毕业季你考虑好去留了吗
--都市修炼手册之SQL-- 第一章 基础复习
MOS管防倒灌电路设计及其过程分析
快速生成1~20自然数,并轻松复制
SPI protocol
Set set!! Review quickly -- MySQL addition, deletion, modification and query, internal, left and right connection review notes
shell正则表达式
数组中的第K个最大元素
[flower carving experience] 11 start esp32c3
Laravel basic course routing and MVC - controller
I2C protocol
剑指 Offer II 096. 字符串交织
Development and monitoring of fusion experiment pulse power supply by LabVIEW
ETCD数据库源码分析——集群间网络层服务端接口