-
Notifications
You must be signed in to change notification settings - Fork 1
/
PklExporter.py
54 lines (41 loc) · 1.59 KB
/
PklExporter.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
import datetime
import pickle
import csv
def export_data(pickle_file, csv_file):
with open(pickle_file, 'rb+') as file:
frames = pickle.load(file)
with open(csv_file, 'x+', newline='\n') as csvFile:
writer = csv.writer(csvFile)
# write the header
writer.writerow(['time_instant', 'frame_number', 'object_number', 'x (m)', 'y (m)', 'z (m)', 'doppler (m/s)'])
counter = 1
for frame in frames:
for tlv in frame.tlvs:
objs = tlv.objects
if tlv.name == 'DETECTED_POINTS':
inner = 1
for obj in objs:
x = obj.x
y = obj.y
z = obj.z
speed = obj.doppler
# write each row
if frame.time is None:
frame.time = datetime.datetime.now()
writer.writerow([frame.time, counter, inner, x, y, z, speed])
inner += 1
counter += 1
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser(description='Run the pkl to csv exporter')
parser.add_help = True
parser.add_argument('--file', help='Pickle File name to export')
args = parser.parse_args()
output_filename = args.file.split('.')
if len(output_filename[0]) == 0:
output_filename = output_filename[1]
else:
output_filename = output_filename[0]
print(output_filename)
output_filename += '.csv'
export_data(args.file, output_filename)