说明
1、模板匹配不支持放大缩小,图像旋转,不适用于缩放与旋转情况;应保证模板图像与搜寻的图像具有相同的大小,方向;
2、模板匹配用来寻找一幅图像中与模板最匹配的部分,模板图像大小必须小于搜寻的原图像,且类型必须相同;
3、CvInvoke.MatchTemplate()函数:输出比较映射图像result类型为:32位单通道图像,尺寸大小为 : (W-w+1)*(H-h+1);映射图像结果中最佳匹配的地方最亮,图像像素值最大;可先将映射图像归一化到0-1,再寻找maxLoc与maxValue,设定一个阈值,大于阈值的认为是匹配图像结果(实现多模板匹配);匹配方法常用:CcorrNormed(归一化相关匹配法)


4、CvInvoke.MinMaxLoc() : 寻找图像中最大最小像素值及其位置;

Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Emgu.CV;
using Emgu.Util;
using Emgu.CV.Util;
using Emgu.CV.CvEnum;
using Emgu.CV.Structure;
using System.Drawing;
namespace lesson20
{
class Program
{
static void Main(string[] args)
{
///单模板匹配
//Mat src = CvInvoke.Imread("src.png");
//CvInvoke.Imshow("src", src);
//Mat result = src.Clone();
//Mat tempImg = CvInvoke.Imread("temp.png");
//int rows_dst = src.Rows - tempImg.Rows + 1;
//int cols_dst = src.Cols - tempImg.Cols + 1;
//Mat dst = new Mat(rows_dst,cols_dst,DepthType.Cv32F,1); //创建合适大小的32位浮点型单通道图像
//CvInvoke.MatchTemplate(src, tempImg, dst

本文深入探讨了模板匹配技术在图像处理中的应用,包括其限制、实施步骤及多种匹配方法。重点介绍了CvInvoke.MatchTemplate()函数的使用,以及如何通过归一化、MinMaxLoc()函数确定最佳匹配位置。同时,文章提供了单模板、视频模板和多模板匹配的代码实例。
最低0.47元/天 解锁文章
5279

被折叠的 条评论
为什么被折叠?



