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.41k stars 247 forks source link

Is there a link between detections and tracked_objects. (maintain order) #254

Closed Edohvin closed 1 year ago

Edohvin commented 1 year ago

Imagine there are 3 bounding boxes in 'detections' and 2 items in 'tracked_objects' (because one object is still uninitialized).

tracked_objects = tracker.update(detections=detections)

Is there any way to know which item in detections is uninitialized (not yet alive)?

Extra info: I am basically looking for a link between the input and the output. I want to achieve the output (tracked_objects) to be also of length 3, and just have None in there. So for example [obj1(...), none, obj2(...)]. This makes it clear that the second bounding box from the detections variable is the item that is still initializing. I also don't want object_ids for objects that have just left the frame (I guess sometimes tracked_objects can be larger than detections because of objects that just left the frame but still have a hit counter).

facundo-lezama commented 1 year ago

Hi @Edohvin,

norfair.update() returns only the live objects, but if you need to debug the uninitialized objects, you can access the complete list of objects on tracker.tracked_objects. Please consider that this list does not follow the detections list order but instead is ordered by ID. If you need to check which detection matched each tracked object, you may use tracked_object.last_detection.

Regarding your last comment on the length of the lists, please note that objects don't disappear instantly; instead, their life is controlled by the hit_counter_max, so you may still see some objects for a while that have left the frame.

Edohvin commented 1 year ago

@facundo-lezama

I used tracked_object.last_detection.points to get the xy coordinates of each tracked object. Then I compared these xy coordinates to the xy coordinates of all the bounding boxes. This allowed me to link what bounding boxes corresponded to which trackids. Not sure if this is the most calculation efficient, but it got the job done! Thank you