rlabbe / filterpy

Python Kalman filtering and optimal estimation library. Implements Kalman filter, particle filter, Extended Kalman filter, Unscented Kalman filter, g-h (alpha-beta), least squares, H Infinity, smoothers, and more. Has companion book 'Kalman and Bayesian Filters in Python'.
MIT License
3.23k stars 614 forks source link

Help needed with adaptive filtering #212

Closed kvnsng closed 3 years ago

kvnsng commented 3 years ago

Hi,

Thanks for this wonderful package. I'm trying to implement a kalman filter for tracking objects that I detect in videos. However, I'm having trouble with trying to implement a working adaptive filter/multiple interacting filters for my case.

For example, if I have a car running into a wall, I'd like to be able to track that over the video. Currently, I'm using batch_filter and rts_smoother to smooth out all the detection noise. However, when a car runs into a wall, the smoothing function doesn't seem to be able to deal with the sudden change in the object's momentum. Could you please point me in the right direction on how to solve this problem? I'm using the smoothing function to deal with all the wonky detection noise in object detection failures, but then with the car running into a wall, the smoother is definitely oversmoothing the location. I'd greatly appreciate any guidance. Thank you!

rlabbe commented 3 years ago

You need to model Q to allow for massive deceleration. if you do that then the rts_smoother will deal with the change better.

But realistically you are in a different regime where Q is not going to allow you to make good estimates during and after a collision. You need to look at things like IMM. Or, at work I have had great success with collisions using MHT - multiple hypothesis tracking. When you think there is a possibility of a collision, the tree branches - one filter predicting no collision, another filter predicting the collision (and realisitically, another branch to account for the possibility you got no detection at all). And then you deal with this probabistically. Each branch of the tree computes it's own probability. It's way past the topic of this library or the companion book. Samual Blackman has outstanding publications on the topic of MHT, and it is primarily what I used for this problem.

You are outside the realm of simple textbook problems of feeding data into a linear algebra engine, and in the realm of dealing with messy statistical spaces.