Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import cv2
- from PIL import Image
- import keyboard
- import mss
- import pyautogui
- import time
- template = cv2.imread("ar.png", 0)
- w, h = template.shape[::-1]
- with mss.mss() as sct:
- monitor = {"top": 0, "left": 0, "width": 1600, "height": 900}
- while "Screen capturing":
- last_time = time.time()
- img = np.array(sct.grab(monitor))
- gray_frame = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
- res = cv2.matchTemplate(gray_frame, template, cv2.TM_CCOEFF_NORMED)
- loc = np.where(res >= 0.73)
- for pt in zip(*loc[::-1]):
- if keyboard.is_pressed('7'):
- pyautogui.click(pt[0]+(w/2), pt[1]+(h))
- print("fps: {}".format(1 / (time.time() - last_time)))
- key = cv2.waitKey(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement