import time
import win32api, win32con
import os
from PIL import Image
from PIL import ImageGrab
import numpy as np
import cv2
from pprint import pformat
box = (289, 90,1067, 710)
img_hhh = cv2.imread('C:/jdws/Screenshot_1.png', 0)
def locate_image(template, threshold=0.8):
screenshot = ImageGrab.grab(box)
screenshot = np.array(screenshot)
screenshot = cv2.cvtColor(screenshot, cv2.COLOR_RGB2BGR)
screenshot_gray = cv2.cvtColor(screenshot, cv2.COLOR_BGR2GRAY)
result = cv2.matchTemplate(screenshot_gray, template, cv2.TM_CCOEFF_NORMED)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
if max_val >= threshold:
return (max_loc[0], max_loc[1])
else:
return None
while True:
vosem_loc = locate_image(img_hhh)
if vosem_loc:
rock = print(vosem_loc)
time.sleep(1)
win32api.SetCursorPos(vosem_loc)