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.66 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.  
  8. template = cv2.imread("img.png", 0)
  9. w, h = template.shape[::-1]
  10.  
  11. with mss.mss() as sct:
  12. monitor = {"top": 0, "left": 0, "width": 1600, "height": 900}
  13.  
  14. while "Screen capturing":
  15.  
  16. img = np.array(sct.grab(monitor))
  17. gray_frame = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
  18. res = cv2.matchTemplate(gray_frame, template, cv2.TM_CCOEFF_NORMED)
  19. loc = np.where(res >= 0.73)
  20. for pt in zip(*loc[::-1]):
  21. if keyboard.is_pressed('7'):
  22. pyautogui.click(pt[0]+(w/2), pt[1]+(h))
  23. key = cv2.waitKey(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement