The OpenCV framework offers many 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 ...