У меня есть мое основное изображение:
![enter image description here](https://i.stack.imgur.com/sTbZB.png)
И мой шаблон:
![enter image description here](https://i.stack.imgur.com/9Ae7W.png)
Однако код cv2, который я использую, не генерирует прямоугольник, чтобы показать наличие совпадения, но я также получаю 0 ошибок.
Вот код:
# Read the main image
img_rgb = cv2.imread('main.png')
# Convert it to grayscale
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
# Read the template
template = cv2.imread('temp.png',0)
template = np.array(template[:,::-1])
# Store width and height of template in w and h
w, h = template.shape[::-1]
# Perform match operations.
res = cv2.matchTemplate(img_gray, template, cv2.TM_CCOEFF_NORMED)
# Specify a threshold
threshold = 0.8
# Store the coordinates of matched area in a numpy array
loc = np.where( res >= threshold)
# Draw a rectangle around the matched region.
for pt in zip(*loc[::-1]):
cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0,255,255), 2)
# Show the final image with the matched area.
cv2.imshow('Detected',img_rgb)
cv2.waitKey()
cv2.destroyAllWindows()
Мои первые мысли о том, что изображение шаблона слишком велико, чтобы соответствовать основному, однако это мой первый go с cv2, и я не уверен, как это исправить.