Object Tracking Using Kalman Filter
Object Tracking Using Kalman Filter
the moving object at each frame. The yellow circle denotes our
detection.
Fig. 1. Four sample frames of the video. In other words, these are four noisy
measurements of the background (which is a 2D signal).
B. Kalman Filter
In this section we describe the formulation and system
Fig. 4. One realization of the noise after quantization.
model for Kalman filter.
Intutitively, Kalman filter takes the current state of your
system, and makes a prediction based on the current state
and current uncertainty of our measurements, and make a Then, it compares its prediction with the received input and
prediction for the next state of the system with anuncertainty. correct it self upon the error.
3
Frame No. : 15 So, the following model can be used to define the state
transition:
1 2
xt 1 0 T 0 xt1 2T
yt 0 1 0 T yt1 1 T 2
=
xt 0 0 1 0 xt1 + T .a+ Wt1 (11)
2
yt 0 0 0 1 yt1 T
We can formulate (11) as follows:
Frame No. : 45
Xt = AXt1 + But1 (12)
Where But1 can be seen as the noise(or external force on
the acceleration).
In this project, we are observing the position of the moving
object. Therefore, we define the following measurement matrix
H:
1 0 0 0
H= (13)
0 1 0 0
Fig. 5. Four sample frames of the video. In other words, these are four noisy The measurement matrix is:
measurements of the background (which is a 2D signal).
xt
xt 1 0 0 0
yt + Vt
= (14)
yt 0 1 0 0 xt
First we need to define our state for the Kalman filter. We yt
want to predict the position of a moving object based on the
Where V = [N (0, 12 ), N (0, 22 )]T is the measurement noise.
current information of the object. For simplicity we assume
Basically, Kalman filter has three noise covariance matrices:
a constant velocity model for our problem. The dynamics of
a moving object in one-dimension can be described as follows:
Dynamic Noise: During transition from one state to
1 2 another, the system can be disturbed by an external force
xt = aT + vt1 T + xt1 (8) and add noise to the system. An external force can be
2
modeled as a disturbance to the object acceleration in
vt = aT + vt1 (9) our problem. It contributes to the prediction of the next
error covarinace matrix.
Where xt and vt denotes the position and velocity at time t, Measurement Noise: All of our sensors are prone to
and a denotes the acceleration. So, the dynamics of a moving noise and consequently will lead to a corruption of
object in one-dimension can be modeled by the position our measurements. We refer to this disturbance as the
and the first derivation of it. Without losing the generality, Measurement Noise.
we can extend the one-dimensional case to a 2D object and Covariance of State Variables
conclude that the dynamics of a two-dimensional object can Assuming that the state variables are independent, we initialize
be described by x, y, x, and y. the covariance matrix of state variables as follows. Please
We define the state Xt with the following variables of interest: note that we can also consider this matrix as posteriori error
covariance matrix.
2
x 0 0 0
xt 0 y2 0
yt 0
St = 2
(15)
Xt =
xt
(10) 0 0 x 0
0 0 0 y2
yt
Also, we further assume that the measurement noises are
Next, we need to see what is the expected behaviour of our independent, then the covariance matrix of V can be described
variables when we are going from one state to another. Based as: 2
on Eq. (8) and (9), we define the following behaviour for the 1 0
cov(V) = R = (16)
system variables: 0 22
1 Finally we need to define the covariance matrix of dynamic
xt = xt1 + xt1 T + aT 2 noise. As it was described earlier, this noise represents the
2
1 2 disturbance during transition from one state to another. It can
yt = yt1 + yt1 T + aT be written as:
2 2
xt = xt1 T + aT x 0 xx 0
yt = yt1 T + aT
0 y2 0 yy
Q= (17)
xx 0 x2 0
0 yy 0 y2
4
St = ASt1 AT + Q
Correction : Frame No. : 17 Frame No. : 21
III. R ESULTS
In order to observe the behaviour of Kalman filter under
Frame No. : 36 Frame No. : 100
different circumstances, we considered three different cases to
examine the Kalman filter in object tracking. In the following
subsections, we examine each of these cases.
A. Scenario 1: Prediction
The first scenario is the case that we are sensing the position
of the object every 3 frames and we want to have a good
prediction of the position of moving object based on these
samples. Fig. 6, illustrates the result in four different frames. Fig. 7. Scenario 2 in which the Kalman filter tracks the moving object in the
The yellow circle is our main tracker(which is used as the presence of a large noise.
input to the Kalman filter every 3 frames) and the black circle
is the prediction of Kalman filter. It can be observed that the
Kalman filter is tracking the moving object with a very good C. Scenario 3: Blind Prediction
accuracy.
In this case, we let the Kalman filter to learn for half of the
B. Scenario 2: Prediction In The Presence of Noise frames and then we did not update the input for the filter. In
(10) we defined the dynamic of the system for the constant
In this scenario, we add a large noise to the input of the velocity object. That is, we are not capturing the acceleration
Kalman filter. It turns out that the Kalman filter is more of the system. So, we should expect that the Kalman filter can
robust to the noise than the original tracker. So, if we have not track the trajectory of the ball because the object is under
our measurements aren corrupted by noise, one can use the the gravity and has a negative vertical acceleration. If we want
Kalman filter to obtain a better estimation than each of the to track the trajectory of the without the input, we must use a
sensors (data fusion) because this algorithm is an adaptive more complex system model as follows:
filter and is more robust to the noise than each of the sensors.
Fig. 7, illustrates this scenario. It can be seen that, the yellow
x
circle is jumping around and is far from the object. However, y
the Kalman filter has a better estimation of the position. Please
x
note that, a low gain will smooth out the noise but also lowers X= y
(20)
the speed of Kalman filter (it will detect the changes more
x
slowly). y
5
Fig. 8. Scenario 3 in which the Kalman filter blindly track the moving object.
IV. C ONCLUSION
In this project we designed a Kalman filter to track a moving
object in a video. In fact, as it was mentioned earlier, a moving
object in a video can be seen as a noise to the background
scene. So, this project was simply a noise detection based on
Kalman filter. The same approach can be used to estimate and
cancel out the noise of other signals. As we saw in the scenario
1 and 2, Kalman filter can be used whenever we need to predict
the next state of a system based on some noisy measurements.
Also, it can be used for sensor fusion as well. It must be
mention that this algorithm is defined for linear systems(we
used linear algebra). In the case if nonlinear systems, the
extended Kalman filter (EKF) which is a nonlinear version
of Kalman filter can be used.