-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoreScriptModi.py
More file actions
98 lines (76 loc) · 2.49 KB
/
Copy pathcoreScriptModi.py
File metadata and controls
98 lines (76 loc) · 2.49 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import numpy as np
import cv2
import time
#import pyautogui
from directKeys import PressKey, ReleaseKey, W, A, S, D
from captureScreen import grab_screen
from getKeys import key_check
import os
from PIL import Image
from keras import backend as K
def presskeys_to_keystrokes(keys):
#[A, W, D]
keystrokes = [0, 0, 0]
if 'A' in keys:
keystrokes[0] = 1
elif 'D' in keys:
keystrokes[2] = 1
else:
keystrokes[1] = 1
return keystrokes
path = os.getcwd()
data_path = path + '/data'
data_dir_list = os.listdir(data_path)
def screen_record():
lc = 0
rc = 0
sc = 0
count = 0
for i in list(range(4))[::-1]:
print(i + 1)
time.sleep(1)
# 800x600 windowed mode
while(True):
last_time = time.time()
screen = grab_screen(region=(0, 400, 800, 600))
#screen = cv2.cvtColor(screen, cv2.COLOR_BGR2GRAY)
screen = cv2.resize(screen, (128, 128))
keys = key_check()
keystrokes = presskeys_to_keystrokes(keys)
#print("Frames capturing at {} fps".format(1.0 / time.time()-last_time))
last_time = time.time()
path = "C:/Users/ajeya/PycharmProjects/Self Driving Car/data"
name = 'image'+str(count)+'.png'
if 'A' in keys:
lc += 1
name = 'image'+str(lc)+'.png'
print(keys)
path = path + "/left"
cv2.imwrite(os.path.join(path, name), screen)
elif 'W' in keys:
sc += 1
name = 'image'+str(sc)+'.png'
print(keys)
path = path + "/straight"
cv2.imwrite(os.path.join(path, name), screen)
elif 'D' in keys:
rc += 1
name = 'image'+str(rc)+'.png'
print(keys)
path = path + "/right"
cv2.imwrite(os.path.join(path, name), screen)
else:
print(keys)
path = path + "/slow"
pass
#cv2.imwrite(os.path.join(path, name), screen)
count += 1
#new_img = cv2.resize(screen,(500,400))
#backtorgb = cv2.cvtColor(new_screen, cv2.COLOR_GRAY2RGB)
#cv2.imshow('Window', cv2.cvtColor(screen, cv2.COLOR_BGR2RGB))
cv2.imshow('window', screen)
#cv2.imwrite(os.path.join(path,name), new_screen)
if cv2.waitKey(25) & 0xFF == ord('q'):
cv2.destroyAllWindows()
break
screen_record()