I am trying to match the following image
With the following templates, using cv2.matchTemplate
#elementachercher = path to template png file
#screenascanner = path to global picture where to find template
import pyautogui
import time
import cv2
import numpy as np
from matplotlib import pyplot as plt
import os
import imutils
def tryfoundobject(elementachercher, screenascanner):
img_rgb = cv2.imread(screenascanner)
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
template = cv2.imread(elementachercher,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_rgb, pt, (pt[0] + w, pt[1] + h), (0,0,255), 2)
if pt != None:
print(elementachercher+" matched")
break
else:
continue
cv2.imwrite(elementachercher,img_rgb)
tryfoundobject("/home/noway/template.png", "/home/noway/mypicture.png")
But no matches are found.
What am I doing wrong? 1 screen is what result i want, the second screen is what i got after script