def matchTemplate(img_full, img_template, meth):
w, h = img_template.shape[::-1]
img = img_full.copy()
# Apply template Matching
method = eval(meth)
res = cv2.matchTemplate(img,img_template,method)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
# If the method is TM_SQDIFF or TM_SQDIFF_NORMED, take minimum
if method in [cv2.TM_SQDIFF, cv2.TM_SQDIFF_NORMED]:
top_left = min_loc
else:
top_left = max_loc
bottom_right = (top_left[0] + w, top_left[1] + h)
return [top_left, bottom_right]
评论列表
文章目录