How do I use OpenCV MatchTemplate?

前端 未结 2 1470
野性不改
野性不改 2020-12-06 01:55

I\'m attempting to find an image in another.

im = cv.LoadImage(\'1.png\', cv.CV_LOAD_IMAGE_UNCHANGED)
    tmp = cv.LoadImage(\'e1.png\', cv.CV_LOAD_IMAGE_UN         


        
2条回答
  •  有刺的猬
    2020-12-06 02:25

    MatchTemplate returns a similarity map and not a location. You can then use this map to find a location.

    If you are only looking for a single match you could do something like this to get a location:

    minVal,maxVal,minLoc,maxLoc = cv.MinMaxLoc(result)
    

    Then minLoc has the location of the best match and minVal describes how well the template fits. You need to come up with a threshold for minVal to determine whether you consider this result a match or not.

    If you are looking for more than one match per image you need to use algorithms like non-maximum supression.

提交回复
热议问题