Home Template Matching
Post
Cancel

Template Matching

What is Template Matching in OpenCV?

Template matching takes a “sliding window” of our waldo query image and slides it across our puzzle image from left to right and top to bottom, one pixel at a time. Then, for each of these locations, it compute the correlation coefficient to determine how “good” or “bad” the match is.

Template matching can be done by:
cv2.matchTemplate(image, templ, method) -> result where :

  • image : Image where the search is running.
  • templ : Searched template. It must be not greater than the source image and have the same data type.
  • method : Parameter specifying the comparison method. This parameter helps us to find as global minimums(when TM_SQDIFF was used) or maximums(TM_CCORR or TM_CCOEFF was used).
  • result : we can get “min_val”, “max_val”, “min_loc”, “max_loc” by using cv2.minMaxLoc(result).





Result









Implementation

This post is licensed under CC BY 4.0 by the author.