Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add class number in the input and output of the update function. #135

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
output/
mot_benchmark
__pycache__
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
wheel==0.34.2
numpy
filterpy==1.4.5
scikit-image==0.17.2
lap==0.4.0
21 changes: 13 additions & 8 deletions sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import os
import numpy as np
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
import matplotlib.patches as patches
from skimage import io
Expand Down Expand Up @@ -96,6 +95,7 @@ class KalmanBoxTracker(object):
This class represents the internal state of individual tracked objects observed as bbox.
"""
count = 0
countReset = 10000
def __init__(self,bbox):
"""
Initialises a tracker using initial bounding box.
Expand All @@ -114,11 +114,14 @@ def __init__(self,bbox):
self.kf.x[:4] = convert_bbox_to_z(bbox)
self.time_since_update = 0
self.id = KalmanBoxTracker.count
KalmanBoxTracker.count += 1
KalmanBoxTracker.count = (KalmanBoxTracker.count+1) % KalmanBoxTracker.countReset
self.history = []
self.hits = 0
self.hit_streak = 0
self.age = 0
self.original_id = bbox[5]
self.original_conf = bbox[4]


def update(self,bbox):
"""
Expand All @@ -128,6 +131,8 @@ def update(self,bbox):
self.history = []
self.hits += 1
self.hit_streak += 1
self.original_id = bbox[5]
self.original_conf = bbox[4]
self.kf.update(convert_bbox_to_z(bbox))

def predict(self):
Expand Down Expand Up @@ -207,7 +212,7 @@ def __init__(self, max_age=1, min_hits=3, iou_threshold=0.3):
self.trackers = []
self.frame_count = 0

def update(self, dets=np.empty((0, 5))):
def update(self, dets=np.empty((0, 6))):
"""
Params:
dets - a numpy array of detections in the format [[x1,y1,x2,y2,score],[x1,y1,x2,y2,score],...]
Expand All @@ -218,12 +223,12 @@ def update(self, dets=np.empty((0, 5))):
"""
self.frame_count += 1
# get predicted locations from existing trackers.
trks = np.zeros((len(self.trackers), 5))
trks = np.zeros((len(self.trackers), 7))
to_del = []
ret = []
for t, trk in enumerate(trks):
pos = self.trackers[t].predict()[0]
trk[:] = [pos[0], pos[1], pos[2], pos[3], 0]
trk[:] = [pos[0], pos[1], pos[2], pos[3], 0, 0, 0]
if np.any(np.isnan(pos)):
to_del.append(t)
trks = np.ma.compress_rows(np.ma.masked_invalid(trks))
Expand All @@ -243,14 +248,14 @@ def update(self, dets=np.empty((0, 5))):
for trk in reversed(self.trackers):
d = trk.get_state()[0]
if (trk.time_since_update < 1) and (trk.hit_streak >= self.min_hits or self.frame_count <= self.min_hits):
ret.append(np.concatenate((d,[trk.id+1])).reshape(1,-1)) # +1 as MOT benchmark requires positive
ret.append(np.concatenate((d,[trk.id+1], [trk.original_id], [trk.original_conf])).reshape(1,-1)) # +1 as MOT benchmark requires positive
i -= 1
# remove dead tracklet
if(trk.time_since_update > self.max_age):
self.trackers.pop(i)
if(len(ret)>0):
return np.concatenate(ret)
return np.empty((0,5))
return np.empty((0,7))

def parse_args():
"""Parse input arguments."""
Expand Down Expand Up @@ -309,7 +314,7 @@ def parse_args():
plt.title(seq + ' Tracked Targets')

start_time = time.time()
trackers = mot_tracker.update(dets)
trackers = mot_tracker.update(np.hstack((dets, np.zeros((dets.shape[0], 1)))))
cycle_time = time.time() - start_time
total_time += cycle_time

Expand Down