'python template/image similarity in a larger picture

Most neural nets for images are great a detecting objects and labeling them. They can take a picture and label some of the objects in it. -- think yolo5

Template matching, on the other hand, looks for a template that is mostly the same in a larger image. -- opencv2.templateMatching

What I hope to have is something kind of "inbetween" the two version. Given a manual entered template image, give me the Rectangles in a larger picture where this template occurs - but must be scale invariant, and transform invariant (within reason).

The opencv2 version is too strict in what it counts as matches -- 10% size change can make matches fail, slight rotations can cause it to fail. This makes it not robust enough to be useful for.

Take for instance the following (below), where we see highlighted pictures of airplanes. This would be the ideal output. The input would be 1 of the small green squares, ideally any 1 of them would work.

Are there things out there that can do this already? Essentially, a opencv2.templateMatching that is more reasonably "fuzzy".

enter image description here

Or if I was doing this with Balls, I would use as template a picture of a ball or even baseball as a clean template, and then highlight 3 balls in the following image.

I don't need image recognition, I need image...similarity with a given template (that is better than opencv2.templateMatching cause that one is terrible)

enter image description here



Solution 1:[1]

For those interested in the future, I ultimately had to go with a full YOLOv5 network to do a custom training.

I was unable to find a "cheaper" solution.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user1639926