Converted Python Template Matching tutorial into GoLang code
What is template matching?
Template matching is a technique for finding areas of an image that match (are similar) to a template image (patch).
How does it work?
We need two primary components:
- Source image (I): The image in which we expect to find a match to the template image
- Template image (T): The patch image which will be compared to the template image
Our goal is to detect the highest matching area.
What does this program do?
- Loads an input image and a image patch (template)
- Perform a template matching procedure by using the OpenCV function
func MatchTemplate(image Mat, templ Mat, result *Mat, method TemplateMatchMode, mask Mat)
with any of the matching methods (Ccoeff, CcoeffNormed, Ccorr, TmCcorrNormed, Sqdiff, or TmSqdiffNormed) - Normalize the output of the matching procedure
- Localize the location with higher matching probability
- Draw a rectangle around the area corresponding to the highest match
- Testing our program with an input image such as:
- And a template image:
- Gives us the match shown below: