-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
47 lines (39 loc) · 1.31 KB
/
main.py
File metadata and controls
47 lines (39 loc) · 1.31 KB
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
37
38
39
40
41
42
43
44
45
46
47
import cv2 as cv
import numpy as np
import pyautogui
needle_img = cv.imread("acceptButton.jpg")
threshold = 0.6 # Threshold for confidence score
needle_w = needle_img.shape[1]
needle_h = needle_img.shape[0]
def capture_screen():
screen_width, screen_height = pyautogui.size()
screen_image = pyautogui.screenshot()
frame = cv.cvtColor(np.array(screen_image), cv.COLOR_RGB2BGR)
return frame
def mouse_click(x, y):
pyautogui.moveTo(x, y)
pyautogui.click()
print("Clicked at: ", x, y)
def main():
found = False
while not found:
haystack_img = capture_screen()
result = cv.matchTemplate(haystack_img, needle_img, cv.TM_CCOEFF_NORMED)
min_val, max_val, min_loc, max_loc = cv.minMaxLoc(result)
if max_val >= threshold:
found = True
print("Found Accept Button")
top_left = max_loc
bottom_right = (top_left[0] + needle_w, top_left[1] + needle_h)
cv.rectangle(
haystack_img,
top_left,
bottom_right,
color=(0, 255, 0),
thickness=2,
lineType=cv.LINE_4,
)
mouse_click(top_left[0] + needle_w / 2, top_left[1] + needle_h / 2)
else:
print("Searching for Accept Button...")
main()