最近被Halcon中的基于边缘的模板匹配算法吸引到了,故找到了一点点学习资料,供同行参阅,水平有限,大家多包含。本文算法很初级,做入门了解用。原文是英文,所以把原文copy 过来了,另加了一些中文。算法运行效果如下:
【效果还行,只是原理性示意,不要要求太高了哦】
Introduction
Template matching is an image processing problem to find the location of an object using a template image in another search image when its pose (X, Y, θ) is unknown. In this article, we implement an algorithm that uses an object’s edge information for recognizing the object in the search image.
【注意边缘点集的特征:(X, Y, θ) 】
Background
【二大主流模板匹配框架,基于灰度的模板匹配和基于特征的模板匹配,本文的方法属于后者】
Template matching is inherently a tough problem due to its speed and reliability issues. The solution should be robust against brightness changes when an object is partially visible or mixed with other objects, and most importantly, the algorithm should be computationally efficient. There are mainlytwo approaches to solve this problem,gray value based matching (or area based matching) and feature based matching (non area based).
Gray value based approach: In gray value based matching, theNormalized Cross Correlation (NCC) algorithm is known from old days. This is typically done at every step by subtracting the mean and dividing by the standard deviation. The cross correlation of template t(x, y) with a sub image f(x, y) is:
Where n is the number of pixels in t(x, y) and f(x, y). [Wiki]
Though this method is robust against linear illumination changes, the algorithm will fail when the object is partially visible or the object is mixed with other objects. Moreover, this algorithm is computationally expensive since it needs to compute the correlation between all the pixels in the template image to the search image.
Feature based approach:Several methods of feature based template matching are being used in the image processing domain. Likeedge based object recognition where the object edges are features for matching, inGeneralized Hough transform, an object’s geometric features will be used for matching.
In this article, we implement an algorithm that uses an object’s edge information for recognizing the object in a search image. This implementation uses the Open-Source Computer Vision library as a platform.【基于opencv2.0的实现】
The algorithm
【边缘检测是算法的核心,算法思路跟Canny差不多】
Here, we are explaining an edge based template matching technique. An edge can be defined as points in a digital image at which the image brightness changes sharply or has discontinuities. Technically, it is a discrete differentiation operation, computing an approximation of the gradient of the image intensity function.
There are many methods for edge detection, but most of them can be grouped into two categories:search-based and zero-crossing based. Thesearch-based methods detect edges by first computing a measure of edge strength, usually a first-order derivative expression such as the gradient magnitude, and then searching for local directional maxima of the gradient magnitude using a computed estimate of the local orientation of the edge, usually the gradient direction. Here, we are using such a method implemented by Sobel known as Sobel operator. The operator calculates the gradient of the image intensity at each point, giving the direction of the largest possible increase from light to dark and the rate of chang