-
Notifications
You must be signed in to change notification settings - Fork 0
/
open.py
36 lines (27 loc) · 955 Bytes
/
open.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import cv2
import numpy as np
import win32api
import win32con
import keyboard
import pyautogui
import time
def click(x,y):
win32api.SetCursorPos((x,y))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
time.sleep(0.1)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)
# Load the template image
template = cv2.imread('aa.png')
while not keyboard.is_pressed('q'):
# Take a screenshot
screenshot = pyautogui.screenshot(region=(0, 150, 380, 250))
# Convert the screenshot to grayscale
gray = cv2.cvtColor(np.array(screenshot), cv2.IMREAD_COLOR)
# Apply template matching
result = cv2.matchTemplate(gray, template, cv2.TM_CCORR_NORMED)
# Find the maximum value in the result matrix
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
# If the maximum value is above a certain threshold, consider it a match
if max_val > 0.5:
x, y = max_loc
click(x+20 , y+170 )