Skip to content

Commit 4cf262d

Browse files
authored
Adding logging in the Tracker class. !NOT TESTED!
1 parent db765b3 commit 4cf262d

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

iou_tracker.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,32 @@
99
from util import load_mot, iou
1010

1111
class Tracker():
12-
def __init__(self, sigma_l=0, sigma_h=0.5, sigma_iou=0.5, t_max=5):
12+
def __init__(self, sigma_l=0, sigma_h=0.5, sigma_iou=0.5, t_max=5, verbose=False):
1313
self.sigma_l = sigma_l
1414
self.sigma_h = sigma_h
1515
self.sigma_iou = sigma_iou
1616
self.t_max = t_max
1717
self.frame = 0
1818
self.id_count = 0
1919
self.tracks_active = {}
20+
self.verbose = verbose
2021

2122
#Clear the old tracks
2223
def clean_old_tracks(self):
2324
target_frame = self.frame - self.t_max
2425
if self.tracks_active.has_key(target_frame):
26+
if self.verbose:
27+
print("[LOG]: Tracks Deleted: {}".format(self.tracks_active[target_frame].keys()))
2528
del(self.tracks_active[target_frame])
2629

2730
#Retrieve tracks in an correct matching order
2831
def retrieve_tracks(self):
2932
tracks = []
3033
frames = range(self.frame, self.frame - self.t_max, -1)
31-
for frame in frames:
34+
for frame in frames:
3235
if frame in self.tracks_active:
36+
if self.verbose:
37+
print("[LOG]: Frame {} Tracks Retrieved: {}."format(frame,self.tracks_active[frame].keys()))
3338
tracks += self.tracks_active[frame].items()
3439
return tracks
3540

@@ -46,16 +51,23 @@ def track(self, detections):
4651
# get det with highest iou
4752
best_match = max(dets, key=lambda x: iou(track['bbox'], x['bbox']))
4853
if iou(track['bbox'], best_match['bbox']) >= self.sigma_iou:
49-
self.tracks_active[self.frame][id_] = best_match
54+
self.tracks_active[self.frame][id_] = best_match
55+
if self.verbose:
56+
print("[LOG]: Tracke {} updated with bbox: {}".format(id_ , best_match['bbox']))
5057
# remove from best matching detection from detections
5158
del dets[dets.index(best_match)]
5259

5360
#Create new tracks
5461
for det in dets:
5562
self.id_count += 1
5663
self.tracks_active[self.frame][self.id_count] = det
64+
if self.verbose:
65+
print("[LOG]: Tracke {} added with bbox: {}".format(self.id_count, best_match['bbox']))
66+
5767

5868
#Return the current tracks
69+
if self.verbose:
70+
print("[LOG]: Trackes {} returned".format(self.tracks_active[self.frame].keys()))
5971
return self.tracks_active[self.frame]
6072

6173

0 commit comments

Comments
 (0)