Kalman Filter ?

Howdy Kwabena and Ibrahim ( and all users) ,

I’m pretty new to this Kalman filter I’ve just discovered. I read abit about among some discussions there and elsewhere after few searches.

you seemed to talk a bit about this in other posts and so I was wondering if it’d already exist in the python library (because I didn’t found it in the help http://docs.openmv.io/library/index.html )

it seems to be a nice way to smooth curves ( so here to smooth some detected blob trajectories for example ) with less input datas than classic average filters and with better accuracy .

(here a screenshot of a python example I found showing difference between average filters and a Kalman one : )

is this something that could be added in the OpenMV python library ( or maye it already exist and as I’m an absolute noob I missed it :slight_smile: ) ?

Thanks.

( in fact my goal is to smooth a target trajectory and then define an anticipation vector/position … so I was studying some ‘PID’ cases , and thaught maybe a Kalman filter before could help getting better smoothing curve ? Did you already tried to make PID effect and/or Kalman one maybe ? )

Edit : just to add some examples with Opencv and Kalman filter :

http://www.morethantechnical.com/2011/06/17/simple-kalman-filter-for-tracking-using-opencv-2-2-w-code/

Hi,

I can’t add a library for a kalman filter because the method works by weighting input values of a filter by the likelihood that they are correct. So, you need a model for what the expected value should be for the next sensor reading in order to use this method.

For example, let’s imagine you are tracking a ball, you know the direction the ball is heading by looking at the difference in direction between two frames. You can guess then what its position will be in the next frame. This is the model.

Then, when you detect the position of the ball in the next frame you can use the model to weight the input of the detected position by how valid you think it is and then update your tracked average by the new weighted value.

The idea behind this type of filtering is to filter out obvious outliers automatically. The model is what makes this possible. I don’t want to support things in the OpenMV Cam firmware that look at difference over time however. That’s really application specific.

As an implementation guide…

I’d take every new input value and weight that by the model and then keep a list of the last n values and their weights computed against the model. Then the average would be the weighted average of the last n values. The model would be updated given the difference in averages to determine the direction.

I’m not quite sure how you’d use the model in the above ball tracking case to weight things. I guess just seeing how far away the new value from the standard dev of previous results might be good.

As for model initialization I don’t know.

ha ok , thanks for the explanations Nyamekye :slight_smile:

I’ll dig deeper arround this !

Cool, generally, just try to make a method that can predict the next position of what are you trying to do and that will be your model. Then weight each new sampled input by the model and you have a kalman filter. There’s many different ways of doing this and not one code template for it.