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.39k stars 243 forks source link

How to get object/track id and their bbox coordinates for a video? #300

Closed utility-aagrawal closed 7 months ago

utility-aagrawal commented 7 months ago

Hi,

I am using norfair to track faces. I want to know how can I get how many distinct objects are there in my video, bbox coordinates for each object. What's the easiest way to fetch this information? I am looking at the code right now but wanted to post the question here in hope of getting a quick response :)

Thanks!

aguscas commented 7 months ago

At any given moment when you are iterating over the frames of your video, when you call the Tracker.update method it should return a list with all the different objects that still exist.

So when you do

tracked_objects = tracker.update(detections)

you can know the amount of tracked objects at that instant by doing len(tracked_objects), and the coordinates of the bounding box of each tracked object in the current frame is just the TrackedObject.estimate attribute of each TrackedObject element in the tracked_objects list.

for obj in tracked_objects:
    print(f"bbox of object {obj.id}: {obj.estimate}")

I am not sure if this answered your question.

utility-aagrawal commented 7 months ago

It does! Thanks so much, @aguscas !