I am using this tutorial https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_feature2d/py_matcher/py_matcher.html
to match a png in a camera imgage.
It’s amazing and quite simple.
However, I noticed a small issue. Here the sample code: GitHub - egandro/opencv-matcher-test
On I map I have a circle shaped green token. I want to match this. The detectAndCompute functions give me either 0 or 6 keypoints to the template.
That are almost no edges/corners and the whole matching fails.
- What are possible options to fix this?
- I tried several other geometric simple figures (triangle,pentagon,square) and the all fail with low keypoints.
- Template matching is no option, because the tokens are rotated.
What worked very well, adding a Letter “A” or an emticon to the template. I have existing “tokens” e.g. player figures that have that round shape with a white dot.
I am willing to have different detector shape, as I can do a prerun.
Where to start?
I found an issue (fixed).
The template had an alpha layer in the png.
For some strage reasons, alpha is replaced with “black”. I fixed this now it’s white.
There are keypoints but still garbage matches.
As always, posting an example image helps a lot. It’s difficult to have an idea about your exact problem without it.
TemplateMatching is a simple function, so it’s often recommended in tutorials, as it’s easy to explain. However it gives good results only for cases that are very similar: objects of same size, angle, same color (and illumination)…
For more complex cases you might need to use more robust matching functions: SIFT, SURF, ORB… (also part of OpenCV)
here my examples on github - including the the images:
matcher-01 … matcher-05
I am using Sift, Orb and BruteForce.
It works if the template is “more complex”.
For a very simple object like this - opencv-matcher-test/template.png at master · egandro/opencv-matcher-test · GitHub - i get no matches
I don’t understand that.