-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
94 lines (76 loc) · 2.21 KB
/
main.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
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import cv2
import numpy as np
from PIL import ImageGrab
from mss import mss
import SendKeys
import time
from datetime import datetime
cod = []
accel = 170
counta = 0
def findDino():
time.sleep(3)
dinoimg = cv2.imread('dino.png', 0)
w, h = dinoimg.shape[::-1]
img = ImageGrab.grab()
imgcv = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR)
imgcv = cv2.cvtColor(imgcv, cv2.COLOR_BGR2GRAY)
res = cv2.matchTemplate(imgcv, dinoimg, cv2.TM_CCOEFF)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
top_left = max_loc
bottom_right = (top_left[0] + w, top_left[1] + h)
global cod
cod = [top_left[1] + 86, bottom_right[1] - 40, top_left[0] + 450, bottom_right[0] + 350]
def pular():
send = "{SPACE}"
SendKeys.SendKeys(send)
def ajustaImg():
monitor = {'top': cod[1] - 100, 'left': cod[2] - int(accel), 'width': 10, 'height': 100}
with mss() as sct:
imgcv = np.array(sct.grab(monitor))
imgcv = cv2.cvtColor(imgcv, cv2.COLOR_BGR2GRAY)
_, imgcv = cv2.threshold(imgcv, 128, 255, cv2.THRESH_BINARY)
#cv2.imwrite("kappa"+str(counta)+".png", imgcv)
#global counta
#counta += 1
tempoflag = {'top': cod[1] + 100, 'left': cod[2] - int(accel), 'width': 10, 'height': 10}
with mss() as sct:
imgflag = np.array(sct.grab(tempoflag))
imgflag = cv2.cvtColor(imgflag, cv2.COLOR_BGR2GRAY)
_, imgflag = cv2.threshold(imgflag, 128, 255, cv2.THRESH_BINARY)
if cv2.countNonZero(imgflag) > 80:
if cv2.countNonZero(imgcv) < 900:
# print("Jump")
pular()
else:
if cv2.countNonZero(imgcv) > 20:
# print("Jump")
pular()
def tirarPrint():
findDino()
dt = datetime.now().second
count = 0
global accel
accel += 0.05
while (1):
if dt != datetime.now().second:
print(count)
count = 0
dt = datetime.now().second
ajustaImg()
count += 1
tirarPrint()
"""
DEBUG DE FPSTRABSON
def tirarPri nt():
cod = findDino()
dt = datetime.now().second
count = 0
while(1):
if dt != datetime.now().second:
print (count)
count = 0
dt = datetime.now().second
ajustaImg(cod)
count += 1
"""