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

Track future prediction #210

Closed joshfox10 closed 2 years ago

joshfox10 commented 2 years ago

Hi there, I'm curious if there is a way to cleanly predict the future location of the tracked object with the integrated Kalman filter beyond what is used for the next frame?
Thank you.

javiber commented 2 years ago

Hi @joshfox10

Currently, there is no easy way of doing this but the underlying Kalman filter object is available

Assuming you are using the default FilterPyKalmanFilterFactory and not OptimizedKalmanFilterFactory:

ipdb> to = tracked_objects[0]
ipdb> to
Object_1(age: 3, hit_counter: 4, last_distance: 0.29, init_id: 1)
ipdb> to.estimate
array([[1.        , 3.90878529]])
ipdb> to.filter.x
array([[1.        ],
       [3.90878529],
       [0.        ],
       [0.93041352]])
ipdb> for _ in range(5):
    to.filter.predict()

ipdb> to.filter.x
array([[1.        ],
       [8.5608529 ],
       [0.        ],
       [0.93041352]])
ipdb> to.estimate
array([[1.       , 8.5608529]]

Notice that there is no way of predicting steps into the future without affecting the internal state of the filter, this can be a problem if you intend to keep tracking after predicting into the future.

joshfox10 commented 2 years ago

@javiber thanks for your help.