Is there a more efficient way to use Template Matching with images of different sizes? Here is my current Script:
import cv2
import numpy as np
img_bgr = cv2.imread('./full.jpg')
img_gray = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2GRAY)
template = cv2.imread('./template.jpg', 0)
w, h = template.shape[::-1]
res = cv2.matchTemplate(img_gray, template,
cv2.TM_CCOEFF_NORMED)
threshold = 0.8
loc = np.where(res >= threshold)
for pt in zip(*loc[::-1]):
cv2.rectangle(img_bgr, pt, (pt[0]+w, pt[1]+h), (0,255,255), 2)
cv2.imshow('detected', img_bgr)
cv2.waitKey(0)
cv2.destroyAllWindows()
This is my Template: Template
And I have these images, the first one works and the second one does not because of the size:
At first thought, I'm thinking it's failing because of the size of the template vs image
So I tried using this tutorial: Multi Scale Matching
But this seems really slow and bulky especially since I intend to use this in videos when I get it working. Is there a better way to handle this
Also, eventually I would also only like to check the top right of the image, I know that's a completely different question, but if you have any ideas since we're talking about scaling :)