# Trying to match tokens on a playfied

**URL:** <https://forum.opencv.org/t/trying-to-match-tokens-on-a-playfied/1890>\
**Category:** Python\
**Tags:** features2d\
**Created:** [March 1, 2021, 5:08pm UTC](https://forum.opencv.org/t/trying-to-match-tokens-on-a-playfied/1890 "2021-03-01T17:08:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![egandro](https://avatars.discourse-cdn.com/v4/letter/e/f9ae1b/32.png) [@egandro](https://forum.opencv.org/u/egandro)\
**Post date:** [March 1, 2021, 5:08pm UTC](https://forum.opencv.org/t/trying-to-match-tokens-on-a-playfied/1890/1 "2021-03-01T17:08:18Z")

</div>

Hello,

I am using this tutorial [https://opencv-python-tutroals.readthedocs.io/en/latest/py\_tutorials/py\_feature2d/py\_matcher/py\_matcher.html](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](https://github.com/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.

1. What are possible options to fix this?
2. I tried several other geometric simple figures (triangle,pentagon,square) and the all fail with low keypoints.
3. 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?

Thank you 🙂

---

<div class="post-metadata">

**Author:** ![egandro](https://avatars.discourse-cdn.com/v4/letter/e/f9ae1b/32.png) [@egandro](https://forum.opencv.org/u/egandro)\
**Post date:** [March 1, 2021, 9:43pm UTC](https://forum.opencv.org/t/trying-to-match-tokens-on-a-playfied/1890/2 "2021-03-01T21:43:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kbarni](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/kbarni/32/26_2.png) [@kbarni](https://forum.opencv.org/u/kbarni)\
**Post date:** [March 1, 2021, 10:51pm UTC](https://forum.opencv.org/t/trying-to-match-tokens-on-a-playfied/1890/3 "2021-03-01T22:51:02Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![egandro](https://avatars.discourse-cdn.com/v4/letter/e/f9ae1b/32.png) [@egandro](https://forum.opencv.org/u/egandro)\
**Post date:** [March 2, 2021, 12:01pm UTC](https://forum.opencv.org/t/trying-to-match-tokens-on-a-playfied/1890/4 "2021-03-02T12:01:35Z")

</div>

Hello kbarni.

here my examples on github - including the the images:

> **[egandro/opencv-matcher-test](https://github.com/egandro/opencv-matcher-test)**
>
> Contribute to egandro/opencv-matcher-test development by creating an account on GitHub.

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](https://github.com/egandro/opencv-matcher-test/blob/master/template.png) - i get no matches 🙂

I don’t understand that.
