-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgetdata.py
50 lines (43 loc) · 1.17 KB
/
getdata.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
import numpy as np
from PIL import ImageGrab
import cv2
import time
from getkeys import key_check
file = open("G://Works//Chrome T-rex//counter.txt", 'r')
items = file.readlines()
file.close()
counter = []
counter = list(map(int, items))
print(counter)
path = 'G://Works//Chrome T-rex//data//'
up = 38
down = 40
for i in list(range(4))[::-1]:
print(i+1)
time.sleep(1)
last_time = time.time()
while True:
screen = np.array(ImageGrab.grab(bbox=(360,100,700,440)))
screen = cv2.cvtColor(screen, cv2.COLOR_RGB2BGR)
keys = key_check()
if up in keys:
cv2.imwrite(path + 'up/' + str(counter[0]) + ".jpg",screen)
counter[0]+=1
time.sleep(0.5)
elif down in keys:
cv2.imwrite(path + 'down/' + str(counter[1]) + ".jpg",screen)
counter[1]+=1
time.sleep(0.5)
else:
cv2.imwrite(path + 'null/' + str(counter[2]) + ".jpg",screen)
counter[2]+=1
if ord('E') in keys:
break
if cv2.waitKey(25) & 0xFF == ord('q'):
cv2.destroyAllWindows()
break
file = open("G://Works//Chrome T-rex//counter.txt", 'w')
for ch in counter:
print(ch)
file.write(str(ch) + "\n")
file.close()