import cv2
import numpy as np
img = cv2.imread('./image/cat.png')
template = cv2.imread('./image/min-cat.png')
# 匹配
res = cv2.matchTemplate(img,template,cv2.TM_SQDIFF)
# 大小为a-b+1
print(res.shape)
# 拿到最大值、最小值和对应的位置
min_val,max_val,min_loc,max_loc = cv2.minMaxLoc(res)
# 最小值的位置就是匹配的位置
print(min_loc)
# 画出匹配到的位置
cv2.rectangle(img,min_loc,(min_loc[0]+template.shape[1],min_loc[1]+template.shape[0]),(0,0,255),2)
cv2.imshow('img',img)
cv2.waitKey(0)
cv2.destroyAllWindows()