【效果展示】
原图
模板图
匹配结果:
【实现部分代码】
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenCvSharp;
namespace FIRC
{
public partial class Form1 : Form
{
public Dictionary<string, TemplateMatchModes> tmm_dict = new Dictionary<string, TemplateMatchModes>();
public Mat src = null;//存储原图
public Mat template = Cv2.ImRead(Application.StartupPath+"\\images\\template.jpg");
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "(图片文件)*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png"; ;
if (ofd.ShowDialog() == DialogResult.OK)
{
src= Cv2.ImRead(ofd.FileName);
var points = FIRCMatchTemplate.MatchTemplate(src,template,tmm_dict[comboBox1.Text],0.8f);
var resultMat = FIRCMatchTemplate.DrawImage(points,src.Clone(),template.Size());
pictureBox1.Image = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(resultMat);
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if(src!=null)
{
var points = FIRCMatchTemplate.MatchTemplate(src, template, tmm_dict[comboBox1.Text], 0.8f);
var resultMat = FIRCMatchTemplate.DrawImage(points, src.Clone(), template.Size());
pictureBox1.Image = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(resultMat);
}
}
private void Form1_Load(object sender, EventArgs e)
{
tmm_dict.Add("CCoeffNormed",TemplateMatchModes.CCoeffNormed);
tmm_dict.Add("CCoeff", TemplateMatchModes.CCoeff);
tmm_dict.Add("SqDiffNormed", TemplateMatchModes.SqDiffNormed);
tmm_dict.Add("SqDiff", TemplateMatchModes.SqDiff);
tmm_dict.Add("CCorrNormed", TemplateMatchModes.CCorrNormed);
tmm_dict.Add("CCorr", TemplateMatchModes.CCorr);
comboBox1.SelectedIndex = 0;
}
}
}
【测试环境】
vs2019,netframework4.7.2,opencvsharp4.8.0
【视频演示】
C# opencvsharp多目标模板匹配算法演示代码_哔哩哔哩_bilibili测试环境:vs2019,netframework4.7.2,opencvsharp4.8.0, 视频播放量 2、弹幕量 0、点赞数 0、投硬币枚数 0、收藏人数 0、转发人数 0, 视频作者 未来自主研究中心, 作者简介 未来自主研究中心,相关视频:资源软件库学习资料总站大全合集更新,资源软件库学习资料无敌了,C# opencvsharp实现透视变换演示,使用C++部署yolov8的onnx和bytetrack实现目标追踪,基于yolov5的单目测距视频演示,labelme json转yolo工具用于目标检测训练数据集使用教程,基于yolov8+deepsort实现目标追踪视频演示,一个软件库永久更新学习资料资源共享,[数据集介绍][目标检测]城市街道垃圾数据集VOC格式5266张,基于yolov8+deepsort+SLPNet实现车辆检测车辆识别车辆违停指定区域检测一体化系统https://www.bilibili.com/video/BV1Mt421n7fx/
【演示源码下载地址】
https://download.csdn.net/download/FL1623863129/89079647