简体   繁体   中英

Emgu CV - ignore a color while matching template

I'm using Image class and it's MatchTemplate method in Emgu CV to detect pattern in pictures. So, my pictures are black-white (with 256 gray variants) and I have to search for white templates, but how do I store them? If I'm using .png with only 2 colors: white for pattern and black for background - then MatchTemplate method considers the background part of template (and that's ruining the results). What color I have to use for background in patterns?

UPD: Images added.

Pattern (only white triangle needed):

图案

Image example (a simple one):

图片

Detection (white square is what I get, red one - what I need): 检测

Please read this: http://docs.opencv.org/2.4/modules/imgproc/doc/object_detection.html?highlight=matchtemplate#matchtemplate

You obviously don't know how matchTemplate works.

You cannot simply pick one colour for the background to be ignored. The algorithm always calculates some difference measure between template and some image region. Unless image and template background are the same you will always have an influence.

If you want to "ignore" the background you would have to replace the background by the image region for every iteration so the difference of backgrounds becomes 0 or at least the same for every pixel. This doesn't sound very efficient.

Provide input images and template examples. There is most likely a better solution for your problem.

You should probably modify your template image by removing the four black sides, which leaves only the white triangle and the black one. That should help you get your desired result.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM