Question

I am working on a object tracking project and I want to improve the results I am getting using a Kalman filter.

I have found a lot of examples on the internet which are working but I really want to understand what is behind it.

Using opencv, here is a part of the code :

KalmanFilter KF(6, 2, 0);
Mat_ state(6, 1); 
Mat processNoise(6, 1, CV_32F);
...
KF.statePre.at(0) = mouse_info.x;
KF.statePre.at(1) = mouse_info.y;
KF.statePre.at(2) = 0;
KF.statePre.at(3) = 0;
KF.statePre.at(4) = 0;
KF.statePre.at(5) = 0;
KF.transitionMatrix = *(Mat_(6, 6) << 1,0,1,0,0.5,0, 0,1,0,1,0,0.5, 0,0,1,0,1,0, 0,0,0,1,0,1, 0,0,0,0,1,0, 0,0,0,0,0,1);
KF.measurementMatrix = *(Mat_(2, 6) << 1,0,1,0,0.5,0, 0,1,0,1,0,0.5);

This one gives smoother results than a KalmanFilter(4,2,0) but I don't really understand why. Can someone explain me what is behind this (6,6) transition matrix ?

EDIT : The solution is probably here but obviously I am not good enough to find it by myself ...

Thank you for your help.

Was it helpful?

Solution

You have a state vector X made up of 6 components, the first two of which are the x and y position of an object; let's assume that the other 4 are their velocities and accelerations:

X = [x, y, v_x, v_y, a_x, a_y] t

In the Kalman filter, your next state, Xt+1, is equal to the previous state Xt multiplied by the transition matrix A, so with the transition matrix you posted, you would have:

x t+1 = x t + v_x t + 0.5 a_x t

y t+1 = y t + v_y t + 0.5 a_y t

v_x t+1 = v_x t + a_x t

v_y t+1 = v_t t + a_t t

a_x t+1 = a_x t

a_y t+1 = a_y t

Which are the discrete approximation of the equations of an object moving with constant acceleration if the time interval between the two states is equal to 1 (and that's why it makes sense to suppose that the other four variables are velocities and accelerations).

This is a Kalman filter that allows for faster variations in the velocity estimation, so it introduces a lower delay than a (4, 2, 0) filter, which would use a constant velocity model.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top