当前位置:网站首页>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);
}

边栏推荐
- vite打包构建时 @charset utf-8警告问题处理;
- Development and monitoring of fusion experiment pulse power supply by LabVIEW
- [Excel知识技能] Excel数据类型
- leetcode 300. Longest Increasing Subsequence 最长递增子序列 (中等)
- What is the process of opening a mobile card account? Is it safe to open an account online?
- The overall process of adding, deleting, modifying and querying function items realized by super detailed SSM framework
- Oracle数据库完全卸载步骤(暂无截图)
- STM32GPIO
- New library launched | cnopendata wholesale price data of agricultural products
- Technical introduction - detailed explanation of chip manufacturing process
猜你喜欢

Shengxin weekly issue 33

The kth largest element in the array

STM32 key development foundation

Remote incremental synchronization artifact Rsync

Data analysis slicer, PivotTable and PivotChart (necessary in the workplace)

MOS管防倒灌电路设计及其过程分析

Dgus new upgrade: fully support digital video playback function

Oracle数据库开启备份准备工作

Web信息收集,互联网上的裸奔者

Quickly generate 1~20 natural numbers and easily copy
随机推荐
Laravel basic course routing and MVC - controller
--SQL of urban cultivation manual -- Chapter 1 basic review
The kth largest element in the array
《产品思维30讲》精华及感想
Black box test - decision table method of test cases
RT-Thread 项目工程搭建和配置--(Env Kconfig)
Qt Cmake 纯C 代码调用系统控制台输入scanf 及 中文输出乱码
Musk vs. jobs, who is the greatest entrepreneur in the 21st century
SPI protocol
Xinku online | cnopendata text data of IPO declaration and issuance of A-share listed companies
Maze walking
Oracle常用的基础命令
Recognize map
Idempotence of interfaces -- talk about idempotence of interfaces in detail, that is, solutions
Is it safe for flush software to buy stocks for trading? How to open an account to buy shares
containerd客户端比较
在线小工具分享(不定时更新,当前数量:2)
2022 documenter general basic (documenter) exam simulation 100 questions and online simulation exam
物联网?快来看 Arduino 上云啦
Embedded C second learning notes