-
Notifications
You must be signed in to change notification settings - Fork 15
/
tracking.py
59 lines (48 loc) · 1.92 KB
/
tracking.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
from track import Track
import numpy as np
class Tracking(object):
def __init__(self):
self.list_of_tracks = []
self.scaling_measurement = 0.3
self.id_counter = 0
self.threshold_bad_track = 0.85
def get_number_of_tracks(self):
return len(self.list_of_tracks)
def prediction(self):
for track in self.list_of_tracks:
track.predict()
def update(self,bboxes):
association = self.data_association(bboxes)
# print(association)
for pair in association:
bbox = bboxes[pair[0]]
# New track
if pair[1] is -1:
self.id_counter += 1
new_track = Track(bbox,self.id_counter)
self.list_of_tracks.append(new_track)
else:
self.list_of_tracks[pair[1]].update(bbox,self.scaling_measurement)
# Tracking management
for track in self.list_of_tracks:
if not track.has_been_updated:
track.not_updated += 1
track.belief = (track.age - track.not_updated)/track.age
self.list_of_tracks = [x for x in self.list_of_tracks if x.belief > self.threshold_bad_track]
def data_association(self,bboxes):
association= []
for i,box in enumerate(bboxes):
min_distance = 100
match = -1
for j,track in enumerate(self.list_of_tracks):
dx = (track.box.x_center - box.x_center)
dy = (track.box.y_center - box.y_center)
dw = (track.box.width - box.width)
dh = (track.box.height - box.height)
# distance = np.sqrt(dx ** 2 + dy ** 2)
distance = np.sqrt(dx ** 2 + dy ** 2 + dw ** 2 + dh ** 2)
if distance < min_distance:
min_distance = distance
match = j
association.append([i,match])
return association