简体   繁体   English

防止不正确的模板匹配OpenCV

[英]Preventing Incorrect Template Matching OpenCV

I am using template matching in a project to find all the locations of a subimage in larger images. 我在项目中使用模板匹配来查找较大图像subimage所有位置。 I am using the OpenCV methods templateMatch() and floodFill() (in Java) to accomplish this, and it is working properly, but only for larger images that DO contain the subimage . 我正在使用OpenCV方法templateMatch()floodFill() (在Java中)来完成此操作,并且它工作正常,但仅适用于确实包含subimage较大subimage

Imgproc.matchTemplate(image, subimage, result, Imgproc.TM_CCOEFF);

If the larger image doesn't contain it, I am returned a huge list of incorrect locations. 如果较大的图像不包含该图像,则会返回大量错误位置的列表。 I want all the locations (if the subimage exists in the larger image), but NONE if it doesn't. 我想要所有位置(如果子图像存在于较大图像中),但是如果没有,则为NONE。 How should I go about doing this? 我应该怎么做呢? And if template matching is not the correct way to do it, what way should I do it then? 如果模板匹配不是正确的方法,那我应该怎么做呢?

Btw my code is structured like this Java opencv template matching and floodfill behavior. 顺便说一下,我的代码的结构像这样的Java opencv模板匹配和泛洪行为。

All help is much appreciated! 非常感谢所有帮助!

There is way you can try, I know the problem which you mentioned, anyway, I found a solution for this, which is you can do threshold operation on the result image, for example the template match when find any match in image of a sumimage , then the position will shows in white color, when it founds good match the color can be more white, so you can threshold the image extract the good found position, and after you can do find contours or some other operation to get the contour position. 有一种方法可以尝试,我知道您提到的问题,无论如何,我找到了解决方案,即您可以对结果图像进行阈值运算,例如,在sumimage图像中找到任何匹配项时进行模板匹配,然后该位置将以白色显示,当找到匹配好的颜色时,颜色可以更白,因此您可以对图像进行阈值提取,以找到合适的位置,然后可以找到轮廓或进行其他操作以获取轮廓位置。 Hope it can help you! 希望它能对您有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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