Skip to content

Commit

Permalink
store matched detections ids in tracker instance (#25)
Browse files Browse the repository at this point in the history
* store matched detections ids in multi object tracker instance
  • Loading branch information
kha-white authored Feb 4, 2022
1 parent da0a21c commit c77f85d
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions motpy/tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,8 @@ def __init__(self, dt: float,
self.active_tracks_kwargs: Dict = active_tracks_kwargs if active_tracks_kwargs is not None else {}
logger.debug('using active_tracks_kwargs: %s' % str(self.active_tracks_kwargs))

self.detections_matched_ids = []

def active_tracks(self,
max_staleness_to_positive_ratio: float = 3.0,
max_staleness: float = 999,
Expand Down Expand Up @@ -399,10 +401,13 @@ def step(self, detections: Sequence[Detection]) -> List[Track]:
matches = self.matching_fn(self.trackers, detections)
logger.debug('matched %d pairs' % len(matches))

self.detections_matched_ids = [None] * len(detections)

# assigned trackers: correct
for match in matches:
track_idx, det_idx = match[0], match[1]
self.trackers[track_idx].update(detection=detections[det_idx])
self.detections_matched_ids[det_idx] = self.trackers[track_idx].id

# not assigned detections: create new trackers POF
assigned_det_idxs = set(matches[:, 1]) if len(matches) > 0 else []
Expand All @@ -412,6 +417,7 @@ def step(self, detections: Sequence[Detection]) -> List[Track]:
score0=det.score,
class_id0=det.class_id,
**self.tracker_kwargs)
self.detections_matched_ids[det_idx] = tracker.id
self.trackers.append(tracker)

# unassigned trackers
Expand Down

0 comments on commit c77f85d

Please sign in to comment.