import cv2, pyautogui
template = cv2.imread("template.png", 0) # read as gray scale
x_screen, y_screen, w_screen, h_screen = 0, 0, 1920, 1080
# (x_screen, y_screen) is the origin of the screenshot. In this case:topleft
while True: # first loop taking screenshots
pyautogui.screenshot("image.png", (x_screen, y_screen, w_screen, h_screen))
screenshot = cv2.imread("image.png", 0)
#saves screenshots as image.png and overwrites it each time
while True: # loops many times tru each screenshot looking for template match
result = cv2.matchTemplate(screenshot, template, cv2.TM_CCOEFF_NORMED) ]
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
if max_val >= 0.8: #0.8 here is the threshold. change as you prefer.
print("match at ", max_loc, end = "\r")
break # breaks match template loop and go back to screnshot loop
else:
print("no match", end = "\r")
break # breaks match template loop and go back to screnshot loop