简体   繁体   中英

Preventing Incorrect Template Matching OpenCV

I am using template matching in a project to find all the locations of a subimage in larger images. 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 .

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. 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.

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. Hope it can help you!

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