-
Notifications
You must be signed in to change notification settings - Fork 3
/
VizualizeDrivingPath.py
92 lines (76 loc) · 3.3 KB
/
VizualizeDrivingPath.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
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
import math
import pickle
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.patches as mpatches
class VizualizeDrivingPath:
def __init__(self):
self.speedsChasing = []
self.filePathChasing = 'chasingLog.p'
self.speedsChased = []
self.filePathChased = 'chasedLog.p'
self.distances = []
self.filePathDistances = 'distancesLog.p'
self.angles = []
self.filePathAngles = 'anglesLog.p'
self.counter = 0
def Add(self, velocity3DChasing, velocity3DChased, distance, angleBetweenTwoCars):
speed1 = 3.6 * math.sqrt(velocity3DChasing.x*velocity3DChasing.x + velocity3DChasing.y*velocity3DChasing.y + velocity3DChasing.z * velocity3DChasing.z)
speed2 = 3.6 * math.sqrt(velocity3DChased.x*velocity3DChased.x + velocity3DChased.y*velocity3DChased.y + velocity3DChased.z * velocity3DChased.z)
self.speedsChasing.append(speed1)
self.speedsChased.append(speed2)
self.distances.append(distance)
self.angles.append(angleBetweenTwoCars)
self.counter += 1
if self.counter % 200 == 0:
self.Save()
def Save(self):
pickle.dump( self.speedsChasing, open(self.filePathChasing, "wb" ) )
pickle.dump( self.speedsChased, open(self.filePathChased, "wb" ) )
pickle.dump( self.distances, open(self.filePathDistances, "wb" ) )
pickle.dump( self.angles, open(self.filePathAngles, "wb" ) )
def Load(self):
self.speedsChasing = pickle.load(open( self.filePathChasing, "rb" ))
self.speedsChased = pickle.load(open( self.filePathChased, "rb" ))
self.distances = pickle.load(open( self.filePathDistances, "rb" ))
self.angles = pickle.load(open( self.filePathAngles, "rb" ))
def ShowSpeeds(self):
plt.rc('axes', titlesize=20)
plt.rc('axes', labelsize=18)
X = np.arange(len(self.speedsChasing[45:]))
plt.plot(X,self.speedsChasing[45:],color='green')
plt.plot(X,self.speedsChased[45:],color='blue')
plt.xlabel('Frame number')
plt.ylabel('Speed km/h')
plt.title('Speeds of both vehicles in time')
patchesList = []
patchesList.append(mpatches.Patch(color='green', label='Chasing car'))
patchesList.append(mpatches.Patch(color='blue', label='Chased car'))
plt.legend(handles=patchesList)
plt.show()
def ShowDistances(self):
plt.rc('axes', titlesize=20)
plt.rc('axes', labelsize=18)
X = np.arange(len(self.speedsChasing[45:]))
plt.plot(X,self.distances[45:],color='green')
plt.xlabel('Frame number')
plt.ylabel('Distances between cars in meters')
plt.title('Distances between cars in time')
plt.show()
def ShowAngles(self):
plt.rc('axes', titlesize=20)
plt.rc('axes', labelsize=18)
X = np.arange(len(self.speedsChasing[45:]))
plt.plot(X,self.angles[45:],color='green')
plt.xlabel('Frame number')
plt.ylabel('Angles between cars in degrees')
plt.title('Angles between cars in time')
plt.show()
def LoadMaesFiles(self):
with open('maes_data.txt') as f:
lines = [line.rstrip('\n') for line in f]
# tmp = VizualizeDrivingPath()
# tmp.Load()
# tmp.ShowSpeeds()
# tmp.ShowDistances()
# tmp.ShowAngles()