Ask Your Question
5

kalman filter

asked 2012-11-22 17:04:16 -0600

theodore gravatar image

updated 2012-11-23 18:31:55 -0600

hi to everyone, currently i am working on project where i have to track some blobs in a video sequence and determine when these blobs approaching each other or even to predict possible crash of the blobs. For the detection of the blobs i am using background subtraction and more specifically the integrated Mixture of Gaussian class (i.e. the BackgroundSubtractorMOG2 method). The results are quite nice, so i do not have any problems related to that part, for now :-p. At the end the final information about each blob is extracted by using the contours functions.

Then i have to track these blobs by taking as a reference point the centroid of each blob, which i am extracting by using the moments from the extracted contours. Searching the web and playing around i managed to implement a data association algorithm in order to extract the trajectories of each blob by just using the centroid point and saving this point through the frames to the correspondent blob id. However, this method is quite weak and hard to provide robust results in case of some occlusion or if for some reason the distance between the current centroid point and the previous one is bigger than the threshold that i have specified in order to map each new centroid to one of the blobs. The latter if it fails has as a result to default the previous vector that holds the centroid history of the blob and create a new blob id and creating everything from the beginning. So for that reason i came up with the kalman filter technique, which from what i am reading it can provide me with a certain safety to this kind of problems and furthermore using the prediction part maybe to provide with some prediction information.

After having a look in the theory and knowing that opencv provides a class related to kalman filter i tried to look around for any example which might help me to clear any doubts related to it. However, there is almost nothing, that describes quite step by step how to do it in opencv and especially using the new C++ API of opencv. The only good examples that i came up with are these:

http://www.morethantechnical.com/2011/06/17/simple-kalman-filter-for-tracking-using-opencv-2-2-w-code/ https://code.ros.org/trac/opencv/browser/trunk/opencv_extra/learning_opencv_v2/ch10_ex10_2.cpp

which are more or less describing the basic idea behind kalman but without getting into further details. So, here are coming my questions:

  1. Do you have in mind or have you met any example related to kalman filter and the new C++ API of opencv where you can point me to. If it can handle multiple tracking that would be great :-).
  2. For how far can the kalman filter predict, it is only for the next-time instance or can i get a prediction somehow for two or three time instances after, is there a way to customize this.
  3. In the links above the people are using as ...
(more)
edit retag flag offensive close merge delete

Comments

More questions come in a new Question - not in the same thread.

sammy gravatar imagesammy ( 2013-03-14 08:11:29 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
7

answered 2012-11-22 21:21:03 -0600

Hi Theodore! Wow that was a long question... but as Jack the Ripper said: "Lets go by parts"

  1. Did you check the sample code for Kalman filter that comes with OpenCV-2.4.3? It is located at OpenCV-2.4.3/samples/cpp/kalman.cpp. Also, I recommend you the Unit 2 of Sebastian Thrun's excellent course about Self-driving cars (It is not related to OpenCV but has an outstanding explanation of Kalman filters)

  2. Yes, you can apply the prediction step as many times you want without measuring. But, you should keep in mind that the uncertainty about the position of your tracked object will grow and grow until you provide a measurement.

  3. Including more parameters, just for the sake of it, will not help you without a good prediction model.

  4. It will depend on the covariance matrix, if the parameters are independent then it will make no difference using only one or several kalman filters. But, if the parameters are somehow interrelated then using different kalman filters for each parameter will produce different results as if you were using only one filter for all parameters. I would recommend you to use the same filter for all the parameters.

  5. The answer to this is on the course that I pointed you out before :) Short version: Velocity can be derived from previous positions.

I hope this could shed some light to your doubts. Welcome to the forum.

edit flag offensive delete link more

Comments

Thanks @Martin your answer was quite helpful. Also the class at the Stanford University was a great link. So, to conclude from what i got watching also the class from Stanford is that i need only one filter where i will fit all my different dynamic parameters. For my measurement parameters i will need to pass only the actual values that i am getting for each dynamic parameters excluding the velocity which will be an unknown each time but i will be able to estimate it each time through the kalman fillter. Am i right?

theodore gravatar imagetheodore ( 2012-11-23 06:35:23 -0600 )edit

Yup. That's pretty much it :) Oh! By the way... thanks for posting the example code. It is normal to lose track of the object with a Kalman filter when you hide it (occlude it) behind another object. That is a hard problem, it can be partially solved using Particle Filters (they are explained also on the Stanford class). Basically a particle filter is like (but not quite the same) having multiple kalman filters each one keeping a different hypothesis of where your tracked object is located. That way when the occlusion is gone, it will be likely that some of the "particles" is tracking the correct position of your blob. Good luck!

Martin Peris gravatar imageMartin Peris ( 2012-11-24 04:40:29 -0600 )edit

Question Tools

Stats

Asked: 2012-11-22 17:04:16 -0600

Seen: 8,749 times

Last updated: Mar 14 '13