The OpenCV framework offers different methods for object detection, tracking, and counting. Template matching is one of the most basic methods of object detection in OpenCV, yet, if it's used correctly and in conjunction with good threshold values, it can be used to effectively detect and count objects in an image. It is done by using a single function in OpenCV called the matchTemplate
function.
The matchTemplate
function takes an image as the input parameter. Consider it the image that will be searched for the object (or better yet, the scene that may contain the template) that we are interested in. It also takes a template as the second parameter. This template is also an image, but it's the one that will be searched for within the first image parameter. Another parameter required by this function, which is also the most important parameter and the one that decides the template matching method, is the method
parameter, which can be one of the entries in the cv::TemplateMatchModes...