tryolabs / norfair

Lightweight Python library for adding real-time multi-object tracking to any detector.
https://tryolabs.github.io/norfair/
BSD 3-Clause "New" or "Revised" License
2.42k stars 247 forks source link

Support for object count when using multiple `Tracker` instances #196

Closed javiber closed 2 years ago

javiber commented 2 years ago

This PR includes the new TrackedObjectFactory which is initialized by the Tracker and is in charge of creating new TrackedObjects. This change makes TrackedObject.id unique for each tracker instead of globally unique.

This would allow users to infer the count of objects from the ids (since they are sequential), however, if the count is needed we should directly provide it in the Tracker. For this reason total_object_count and current_object_count are added to the Tracker

Added a new global_id to TrackedObject in case users need something to identify objects accross trackers.

Also included some small changes:

Open questions for reviewers to chime in:

javiber commented 2 years ago

@facundo-lezama I ran this for the yolov5 demo and it worked (with a minor quirk) I was drawing the detections of each tracker in different colors so the result was pretty clear, however, by default the user might get 2 objects with the same id and same color. This makes me wonder if we should draw the global_id instead or even replace the id with the global one. We discussed a lot about having the ids be track-dependent but what is really adding? especially considering that the counts no longer need to be inferred from the ids

The quirk is that there is a small bug that should be solved in #198 (there is some overlap between that PR and this on the validate_points change that I'm going to clean up this tomorrow)

facundo-lezama commented 2 years ago

Nice one, @javiber. That was a smart move!

It's interesting what you say about the ids. I think this change should give the users the flexibility they need to spawn multiple trackers. Let's see how it goes from here, and we may later look back and see if there's something that appears unnecessary.

diegomarvid commented 2 years ago

The name of the PR should be changed before being merged.

Some options:

  1. Differentiate TrackedObjects IDs based on its Tracker
  2. Different ID count for different Trackers

Should we mention the addition of global_id in the PR title? I think we shouldn't because it's what we had before. The new part is being able to differentiate IDs of different Trackers.