python templatematch识别图片

import cv2 as cv
import numpy as np

target = cv.imread("3xs.bmp")
template = cv.imread("322.png")
theight, twidth = target.shape[:2]
result = cv.matchTemplate(target, template, cv.TM_SQDIFF_NORMED)

min_val, max_val, min_loc, max_loc = cv.minMaxLoc(result)

strmin_val = str(min_val)
 


cv.rectangle(template, min_loc, (min_loc[0] + twidth, min_loc[1] + theight), (0, 0, 225), 2)
cv.imshow("MatchResult----MatchingValue="+strmin_val, template)
cv.imwrite('1.png', template, [int(cv.IMWRITE_PNG_COMPRESSION), 9])
cv.waitKey()
cv.destroyAllWindows()

不过缺陷还是不一样的图片像素根本识别不出来     

原文地址:https://www.cnblogs.com/newmiracle/p/13839464.html