Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. import numpy as np
  2. import cv2
  3. from PIL import Image
  4. import keyboard
  5. import mss
  6. import pyautogui
  7. import time
  8.  
  9. template = cv2.imread("ar.png", 0)
  10. w, h = template.shape[::-1]
  11.  
  12. with mss.mss() as sct:
  13. monitor = {"top": 0, "left": 0, "width": 1600, "height": 900}
  14.  
  15. while "Screen capturing":
  16. last_time = time.time()
  17. img = np.array(sct.grab(monitor))
  18. gray_frame = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
  19. res = cv2.matchTemplate(gray_frame, template, cv2.TM_CCOEFF_NORMED)
  20. loc = np.where(res >= 0.73)
  21. for pt in zip(*loc[::-1]):
  22. if keyboard.is_pressed('7'):
  23. pyautogui.mouseUp(button='right')
  24. pyautogui.click(pt[0]+(w/2), pt[1]+(h))
  25. pyautogui.mouseDown(button='right')
  26. print("fps: {}".format(1 / (time.time() - last_time)))
  27. key = cv2.waitKey(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement