pip install opencv-python
temp.png
import cv2
import numpy as np
from matplotlib import pyplot as plt
# 待匹配
img = cv2.imread('1.png', 0)
# 匹配模板
template = cv2.imread('temp.png', 0)
h, w = template.shape
res = cv2.matchTemplate(img,template,cv2.TM_CCOEFF_NORMED)
# 相似度阀值
threshold = 0.7
loc = np.where( res >= threshold)
color = (33, 33, 0)
thickness = 2
for pt in zip(*loc[::-1]):
cv2.rectangle(img, pt, (pt[0] + w, pt[1] + h), color, thickness)
cv2.imshow('thresh', img)
cv2.waitKey()
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。