-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdigits_collect.py
57 lines (44 loc) · 1.48 KB
/
digits_collect.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
from data_collection.img_process import grab_screen
import cv2
import time
from data_collection.key_cap import key_check
import numpy as np
# num1 573:581, 683:688
# num2 573:581, 690:695
# num3 573:581, 697:702
def main():
numbers = []
record = False
i = 0
empty = 0
while True:
time.sleep(0.2)
keys = key_check()
if 'T' in keys:
record = not record
elif 'Z' in keys:
np.save('digits.npy', numbers)
image = grab_screen("Grand Theft Auto V")
# speed
vis = image[568:577, 680:699, :]
vis = cv2.cvtColor(vis, cv2.COLOR_RGB2GRAY)
# ret, vis = cv2.threshold(vis, 140, 255, cv2.THRESH_BINARY_INV)
# ret, vis = cv2.threshold(vis, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
vis = cv2.adaptiveThreshold(vis, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 7, -5)
if record:
i += 1
print(i)
numbers.append(vis[:, :5]) # num1
numbers.append(vis[:, 7:12]) # num2
if empty % 5 == 0:
numbers.append(vis[:, -5:]) # num3
empty += 1
vis = cv2.resize(vis, None, fx=10, fy=10)
cv2.imshow("Frame", vis)
key = cv2.waitKey(1) & 0xFF
# cv2.waitKey()
# if the `q` key was pressed, break from the loop
if key == ord("q"):
break
if __name__ == '__main__':
main()