I have a 7-segment
image, and a template, I've tried to do template matching, but there was no matching for the provided template, can you please tell me how to improve the matching?
- should the template be 100% as same as the desired pattern to be detected in the image?
import numpy as np
import matplotlib.pyplot as plt
import cv2
R = cv2.imread('image.png')
R = cv2.Canny(R, 50, 200)
template = cv2.imread('templ.png',0)
template = cv2.Canny(template, 50, 200)
h, w = template.shape
res = cv2.matchTemplate(R,template,cv2.TM_CCOEFF_NORMED)
threshold = 0.8
loc = np.where( res >= threshold)
for pt in zip(*loc):
cv2.rectangle(R, pt, (pt[0] + w, pt[1] + h), 200, 2)
plt.subplot(221)
plt.imshow(R, cmap='gray')
plt.subplot(222)
plt.imshow(template, cmap='gray')
plt.show()