1

I am trying to match a template with transparency in a scene with OpenCv v3.3.0 I am using the Java example code from the official documentation.

My test case looks like this:

Scene:

Scene

Template with transparency:

Template

Template mask (masked the transparency layer to black):

Mask

Matching result (red border marks the match): Matching result

Expected result (red border marks the expected match): Expected result

For the matching I am using CV_TM_CCORR_NORMED. The matching itself works fine with the mask (without the mask I get a wrong possition). But the found region is the same size as the template and it's mask. I expected it to be the size of the masks colored content.

How can I get the expected results (see image)?

Peter Winzer
  • 165
  • 7

1 Answers1

1

Transparent region means that it can match any pixels as long as those pixels are present. So to make OpenCV find only non-transparent pixels, you need to crop the transparent region on your "query image" first.

anatoly techtonik
  • 19,847
  • 9
  • 124
  • 140