
import cv2
import numpy as np
img = cv2.imread(“yinhua2.png”,)
template = cv2.imread(“yinhua.png”)
result = cv2.matchTemplate(img,template,cv2.TM_SQDIFF_NORMED)
threshold = 0.01
loc = np.where(result <= threshold)
print(*loc[::-1])
for pt in zip(*loc[::-1]):
right_bottom = (pt[0] + w, pt[1] + h)
cv2.rectangle(img, pt, right_bottom,(0, 0,255),2)
cv2.imshow(“img”,img)
cv2.imshow(“template”,template)
cv2.waitKey(0)
cv2.destroyAllWindows()

这篇文章详细介绍了如何使用Python和OpenCV进行图像模板匹配,通过matchTemplate函数找到源图像中与模板相似的部分,并用TM_SQDIFF_NORMED方法进行量化评估。展示了定位并标记匹配区域的过程,适合图像处理初学者和开发者参考。
284

被折叠的 条评论
为什么被折叠?



