Multi-Scale Template Matching

Introduction

It is the implementation of template matching algorithm which is invariant of the size of the template. Here, we will detect cursor on an image. The three cursor template are shown below:

                       


Different Methods

  1. Conventional Template Matching: Implemented in python:
  2. - Template is kept over each pixel to compute correlation.
    - Template should be exactly of the same size of the image patch for this method to perform well.
    - Time consuming due to huge number of computations.

  3. Template matching with Canny edge detector:
  4. - Image and Template are subjected to canny edge detector (using cv2.canny()) and then using cv2.TM_CCOEFF template matching method yields good results.
    - Template need not to be of the same size of the image patch. Muti-scaling template matching is supported.

  5. Template matching with Gaussian Blur and Laplacian transformation:
  6. - Image is subjected to Gaussian blur to reduce noise. Then Laplacian transformation is applied over image and template.
    - Template matching is performed for different scale of template with image by using cv2.TM_CCOEFF matching method.
    - Value returned by matching method is compared with threshold. If the value returned is greater than threshold then the cursor is detected and is shown by the bounded rectangle.
    - This method yields best results. I have implemented cursor detection using this method.


Results

Detected cursor is shown inside bounded blue box on an image.




To check out all the results  Click Here