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

Question regarding the period argument in Tracker update method #241

Closed
romaintha opened this issue Jan 10, 2023 · 2 comments
Closed

Question regarding the period argument in Tracker update method #241

romaintha opened this issue Jan 10, 2023 · 2 comments
Labels
help wanted Extra attention is needed

Comments

@romaintha
Copy link

Hello,
I have a question regarding the period argument in the update method of the Tracker class. When we update the existing tracked objects, if the period is larger than 1, shouldn't we apply the tracker_step on tracked_object as many time as period? Something like this:

        # Update tracker
        for obj in self.tracked_objects:
            for _ in range(period):
                obj.tracker_step()

My initial thought was that if you don't do this, the kalman filter is only predicting the next position for a single period and as a consequence you might have a larger error between measurements and predictions.
Or am I missing something here?

@romaintha romaintha added the help wanted Extra attention is needed label Jan 10, 2023
@DiegoFernandezC
Copy link
Member

Hi @romaintha

The approach for the period parameter to skip frames works a little differently. You can find a demo that uses period here.

The period argument is useful to skip frames and speed up the tracking by running the detector over a few frames.

The short answer is that, is not necessary to call multiple times the tracker_step() because you need to call the tracker.update() method on each frame and the tracker.update() uses the tracker_step() behind the scenes.

On each tracker.update() invocation Norfair runs the tracker_step() method, on this operation Norfair updates some attributes, for example, the hit_counter, and makes a prediction using the Kalman filter for the next position of each object.
As you noticed, this prediction should be executed as many times as the period value to avoid a big error when the detections arrive.
For this reason, the tracker.update() method allows you to not pass detections. This means that you have to run the tracker.update() on every frame. Then, when you get the detections run the tracker.update(detections=detections, period=period) passing the detections to the tracker. This allows Norfair to run the predictions despite not having the detections.

Norfair uses the period argument to compensate the hit_counter to the following tracker.update() invocations without detections.

The code should be looks like this:

for frame in video:
    detections = []
    if frame % period == 0:
        detections = model(frame)
    tracked_objects = tracker.update(detections=detections, period=period)

@romaintha
Copy link
Author

I see. Thank you for your answer @DiegoFernandezC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants