Today, state-of-the-art object detection algorithms (algorithms aiming to detect objects in pictures) are using neural networks such as Yolov4.

Template matching is a technique in digital image processing for finding small parts of an image that matches a template image. It is a much simpler solution than a neural network to conduct object detection. In addition, it comes with the following benefits:

  • no need to annotate data (a time-consuming and mandatory task to train neural networks)
  • bounding boxes are more accurate
  • no need for GPU

In my experience, combining a neural network like Yolov4 and object detection with template matching here is a good way to considerably improve your neural network performance!

What is template matching?

When you use OpenCV template matching, your template slides pixel by pixel on your image. For each position, a similarity metric is computed between your template image and the part of the image it recovers:

template-matching-example

Using template matching to detect French ID in scanned documents

If the similarity metric is high enough for one pixel, then this pixel is probably the top-left corner of an object matching your template!

Consequently, you can achieve object detection with template matching only if the objects you try to detect are similar enough —almost identical— within a class. You can still include more templates to tackle object variations (size, color, orientation). But it will increase the prediction time.

At first look, it seems very restrictive. But a lot of object detection use cases can be tackled with template matching:

  • ID in scanned documents
  • empty parking space from a stationary camera
  • components on an assembly line…

#python #opencv

End-to-end Object Detection with Template Matching using Python
17.40 GEEK