I am trying to find a template in an image and I am using OpenCV for that. The problem is that the TM_SQDIFF function is not exactly what I need and it fails in some cases, for example:
Template:
Image:
Result using SQDIFF:
I want the template to match the bottom right image, because it has more elements that are equal to the template than the result that SQDIFF shows.
What I need seems to be a simpler than the SQDIFF, but I couldn't find a way to do it. Is it possible to do that using OpenCV or another tool in Python?
Ideally I also want to be able to use a mask, because some of the templates are not rectangular.