Search code examples
opencvemgucvmatchtemplate

OpenCV: Match Template, combining close matches


Related to: OpenCv: Finding multiple matches

I am now able to mark where all my matches are. However, because some of the matches aren't perfect, I need to lower my threshold a little. This means that I have bunches of pixels that are all a match for the same item.

So, if the actual match is at 5,5, I have 9 matches in the range of 4,4 to 6,6.

What's the best approach to combining each of those so that I have a single point for each cluster of matches?


Solution

  • You could keep only the best match among all your neighbour matches, i.e. those that are separated by only one pixel.

    One way to do it is to extract the connected components in thresholded image, and for each connected component, look for the location of the lowest value in your result image, and keep it as the "best".