I'm using opencv with python bindings. I'm trying to use the template m开发者_开发技巧atch, but it's not performing exactly as I need it to. If there is no image matching the template I supply it, I don't want it to return a match. It seems to always return a match whether the actual template exists at all in the image I supply it.
I've looked at the documentation for the opencv with Python and can't seem to find any mention of how to set a minimum threshold for matching templates. I need it to be relatively strict when comparing the template to the image.
image = LoadImage("c:/image.png")
template = LoadImage("c:/image-crop2.png")
W,H = GetSize(image)
w,h = GetSize(template)
width = W - w + 1
height = H - h + 1
result = CreateImage((width, height), 32, 1)
MatchTemplate(image, template, result, CV_TM_CCORR)
(min_x, max_y, minloc, maxloc) = MinMaxLoc(result)
(x, y) = minloc
print result
See this answer: OpenCV. Drawing rectangle when matching
You are having exactly the same problem - MatchTemplate
returns a kind of similarity map instead of single match position.
精彩评论