-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayGame.py
More file actions
71 lines (59 loc) · 1.46 KB
/
Copy pathPlayGame.py
File metadata and controls
71 lines (59 loc) · 1.46 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import keyboard
import mss
import cv2
import numpy
from time import time, sleep
import pyautogui
pyautogui.PAUSE = 0
print("Press 's' to start playing.")
print("Once started press 'q' to quit.")
keyboard.wait('s')
left = True
x = 340
y = 850
sct = mss.mss()
dimensions_left = {
'left': 290,
'top': 600,
'width': 150,
'height': 250
}
dimensions_right = {
'left': 520,
'top': 600,
'width': 150,
'height': 250
}
wood_left = cv2.imread('woodleft.jpg')
wood_right = cv2.imread('woodright.jpg')
w = wood_left.shape[1]
h = wood_left.shape[0]
fps_time = time()
while True:
if left:
scr = numpy.array(sct.grab(dimensions_left))
wood = wood_left
else:
scr = numpy.array(sct.grab(dimensions_right))
wood = wood_right
# Cut off alpha
scr_remove = scr[:,:,:3]
result = cv2.matchTemplate(scr_remove, wood, cv2.TM_CCOEFF_NORMED)
_, max_val, _, max_loc = cv2.minMaxLoc(result)
print(f"Max Val: {max_val} Max Loc: {max_loc}")
src = scr.copy()
if max_val > .85:
left = not left
if left:
x=340
else:
x=600
cv2.rectangle(scr, max_loc, (max_loc[0] + w, max_loc[1] + h), (0,255,255), 2)
cv2.imshow('Screen Shot', scr)
cv2.waitKey(1)
pyautogui.click(x=x, y=y)
sleep(.10)
if keyboard.is_pressed('q'):
break
print('FPS: {}'.format(1 / (time() - fps_time)))
fps_time = time()