Member-only story

AI Object Detection the Hard Way

Template Matching or maybe you don’t need Deep Learning yet ?

Keno Leon
7 min readDec 20, 2021

--

Artificial Neural Networks and Deep Learning as amazing as they are currently have some blackbox scent or aroma about them, if pressed ( I’ve been writing about and using them for a while), I’d say they are complex systems for solving problems but I’d be equally hard pressed to recommend them as a cure all for your prediction and detection problems, nothing wrong with them, but sometimes setting them up and monitoring them ends up being quite the task and you might want a simpler alternative, something that you have full control.

Template matching as we will see is one such technique that I think is worth considering and I use it whenever I need a quick detection subsystem for a bigger project or prototype, we will also try to address some of it’s limits and mention some other alternatives…

You can also think about template matching as a precursor/familiar to more advanced ANN Architectures, so without looking at your ANN I'd be willing to bet that at some point there is some template matching happening or at least elements of it.

What is it ?

The name itself is a dead giveaway, in a nutshell you have a template of something you want to detect, an image or other medium ( I’ll be using realtime video ) you want to test for detection and an algorithm that sweeps over the medium ( will be using OpenCV in Python ), if all or some of the individual units match ( pixels in the case of images/video ) you can then detect or predict, or in graphical form.

On the left we have a template for the number three  and on the right a test image with a few numbers including the 3 so we should get a positive match, to do so the algorithm sweeps the template over the test image like so:
Out of the box OpenCV gives you an image as a result where the pixel values correspond to a correlation…

--

--

Keno Leon
Keno Leon

No responses yet