-
Notifications
You must be signed in to change notification settings - Fork 7
/
merge_steering_image_data.py
57 lines (44 loc) · 1.32 KB
/
merge_steering_image_data.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
import sys
import numpy as np
steering = open(sys.argv[1])
camera = open(sys.argv[2])
steering_dict = dict()
time_scale = int(1e8)
to_write_center = open("images_to_angles_center.csv", 'w')
to_write_right = open("images_to_angles_right.csv", 'w')
to_write_left = open("images_to_angles_left.csv", 'w')
for s in steering.readlines():
if 'angle' in s:
continue
s = s.split(',')
timestamp = int(s[0])
angle = float(s[1])
key = (timestamp/time_scale)
if key in steering_dict:
steering_dict[key].append(angle)
else:
steering_dict[key] = [angle]
averaged_angles = dict()
for key in steering_dict:
averaged_angles[key] = np.average(steering_dict[key])
center = dict()
left = dict()
right = dict()
for c in camera.readlines():
if 'filename' in c:
continue
c = c.split(',')
timestamp = int(c[0])
key = (timestamp / time_scale)
if "center" in c[-1]:
center[timestamp] = averaged_angles[key]
elif "left" in c[-1]:
left[timestamp] = averaged_angles[key]
else:
right[timestamp] = averaged_angles[key]
for k in center:
to_write_center.write(str(k) + "," + str(center[k]) + "\n")
for k in left:
to_write_left.write(str(k) + "," + str(left[k]) + "\n")
for k in right:
to_write_right.write(str(k) + "," + str(right[k]) + "\n")