You are on page 1of 5

Research of the Improved Camshift Tracking Algorithm

Xia Liu
1,2
, Hongxia Chu
1
, Pingjun Li
2

Department of Automation and College of Computer Science and Technology, Harbin Engineering University
1

Department of Automation, Harbin University of Science and Technology
2

Harbin 150001, Heilongjiang Province, China
chx0420@163.com

Abstract - In this paper it will introduce the improved
Camshift algorithm based on the Kalman filter, which is applied
to track a moving target. Improved Camshift algorithm is a
algorithm that H, S and V components space is used to track a
moving target in HSV space. The next position of the moving
object is estimated by the Kalman. According to H and S and V,
it can be appropriate to determine the track of moving target.
The algorithm effectively overcomes the shortcoming of the
traditional Camshift algorithm. For example, it is easy to solve
the divergence problem during the tracking. Finally, the
usefulness of algorithm is validated by experiment.

Index Terms - HSV space. Camshift algorithm. Moving target.

I. INTRODUCTION
It is an important issue that the detection and tracking of
moving targets in the visual field of application. Target
tracking is a problem of comprehensive settlement; it involves
image processing, pattern recognition, artificial intelligence,
and adaptive control and so on. In the past years, a lot of
different target tracking algorithm had been proposed, which
is divided into two major ways:
(1) Based on the movement
It mainly relied on vigorous and healthy method, which
can classify the spot with the same movement as the class,
such as optical flow and characteristic point method
[1]
, but
the computational complexity is big.
(2) Based on the model
This approach achieves the target tracking according to
the semantic representation and the description of knowledge
which is using some of the information in the different goals
can be divide into: the method based on the boundary such as
active contour model and the match method of edge based on
Hausdorff distance
[2-3]
; the method based on the target area
which uses the region of the goal as a whole texture
information. It can track the target by much information such
as color and texture to eliminate the background interference
in the out track.
In this paper the next position of the moving object is
estimated by the Kalman filter
[4-5]
. The moving object is
tracked by using the Camshift based on the three components
of the H, S and V.
II KALMAN FILTER
The moving trajectory is gotten in scene based on the
position of every frame. The current position of the object can
be estimated based on the previous positions of the moving
object. So the state value and measured value of the Kalman
filter is the positions.
The two models are included in the Kalman:
Forecasting model:
( ) ( 1) ( 1) ( ) ( ) X k A k X k B k W k = + (1)
Measured model:
( ) ( ) ( ) ( ) Y k C k X k V k = + (2)
Where, ( ) X k , ( ) Y k is the state and measured vector.
( ) 1 A k , ( ) B k , ( ) C k separately is the state transition
matrix, input matrix and observation matrix. ( ) W k and
( ) V k separately is the forecasting noise and measured noise.
State vector is denoted:
( ) ( ) ( ) ( ) ( )
T
X k x k y k x k y k ' ' = (


Where ( ) x k , ( ) y k is the x-coordinate and y-
coordinate. ( ) x k ' and ( ) y k ' is the acceleration of the
moving object.
Measure vector is denoted:
( ) ( ) ( )
T
Y k xc k yc k = (


Where ( ) xc k and is the measured centers of
the object .
( ) yc k
The formula of the moving is as follow:
( ) ( ) ( ) ( )
( ) ( ) ( )
2
1
1 1
2
1
x k x k x k t ax k t
x k x k ax k t
' = + +
' ' = +
(3)
( ) ( ) ( ) ( )
( ) ( ) ( )
2
1
1 1
2
1
y k y k y k t ay k t
y k y k ay k t
' = + +
' ' = +
(4)
Where t is the time interval.
Using (3) and (4), (1) and (2) is separately as follows:
Forecasting model:
( ) ( 1) ( 1) ( ) ( ) X k A k X k B k W k = +
1-4244-0828-8/07/$20.00 2007 IEEE. 968
Proceedings of the 2007 IEEE
International Conference on Mechatronics and Automation
August 5 - 8, 2007, Harbin, China
( )
( )
( )
( )
( )
( )
( )
( )
( )
( )
( )
( )
2
2
0 0 0
1 1 0 0
2
1 0 1 0
0 0 0
1 0 0 1 0 2
0 0 0
1 0 0 0 1
0 0 0
t
x k x k t
y k y k ay k t
t
ax k
x k x k
t
y k y k ay k
t
(
(
( (
(
(
( (
(

(
( (
(
= +
(
( ( ' ' (
(
( (
(
' ' (
( (

(

ax k
(
(
(
(
(
(


Measured model:
( ) ( ) ( ) ( ) ( ) Y k C k X k D k V k = +
( )
( )
( )
( )
( )
( )
( )
1 0 0 0 1 0
0 1 0 0 0 1
x k
xc k y k
V k
yc k x k
y k
(
(
(
( (
(
= +
(
( (
( '


(
'
(


Where is the acceleration. is empirical
value. Supposing the acceleration of the initial several frames
is constant.
( ) W k ( ) V k
The initial value of the moving object can be gotten
based on the formulas:
( ) ( ) ( )
2
1
( 2) 2 1 2
2
x k t ax k t x k x k ' + =
( ) ( ) ( ) ( )
2
1
1 1
2
x k t ax k t x k x k ' + = 1
2

( ) ( ) ( ) 1 2 x k x k ax k ' ' = + t
)

( ) ( 1 2 ax k ax k =
( ) ( ) (
2
1
( 2) 2 1 2
2
y k t ay k t y k y k ' + = )
( ) ( ) ( ) ( )
2
1
1 1
2
y k t ay k t y k y k ' + = 1
2

( ) ( ) ( ) 1 2 y k y k ay k t ' ' = +
( ) ( ) 1 2 ay k ay k =
III IMPROVED CAMSHIFT ALGORITHM
In the latest years, the tracking algorithm of the Camshift is
being concerned because of its practicability and robustness.
Now Camshift has been used on the face tracking by the
perceptual user interface and the semiautomatic object
tracking.
Camshift uses the color feature to track the moving
object. It is a nonparametric technique and uses cluster to find
the moving object
[7]
. The size and position of the moving
object can be obtained by Camshift. The search window of the
next frame can be initialized according to size and position of
the current frame. The object can be continuously tracked
while the process is continuously done. The initial value of the
current search window is set by using the size and position of
the current window before the search begins. Much time is
economized because the moving object is searched around the
position where the object possibly appears. So Camshift has
real time. Because Camshift uses the color feature to track the
moving object, the change of the color feature is very small
when the object is moving. So Camshift has good robustness.
The tracking process of Camshift can be denoted on the Fig.
1.


Fig. 1 The tracking process of Camshift
Before the H(hue) feature is used to tracking the moving
object, but the different objects may have the same H(hue)
value. The improved Camshift algorithm based on the
combination of H, S and V is proposed, which can solve the
shortcoming of the Camshift based on the H feature.

A) Probability Map
The following formula of RGB space charge into HSV
space
[6]
.
( ) ( )
( ) ( )
( ) ( )
max( , , )
3 max , , min , ,
max( , , )
2
3 max , , min , ,
max( , , )
4
3 max , , min , ,
b r
if g r gb
r gb r gb
if b r gb
b r
H
r gb r gb
if r r gb
b r
r gb r gb
t
t
t
| |

=
|
|

\ .

| | =

= +
|
|

\ .

=
| |

+
|
|

\ .
(5)

969
( ) ( )
( )
max , , min , ,
max , ,
r g b r g b
S
r g b

= (6)
max( , , ) V r g = b (7)
Where H representatives hue component, S
representatives color saturation, V representatives luminescent
component. R, g, b represents red, green and blue component.
The model of the HSV is denoted on the Fig. 2.


Figure 2 the model of the HSV
The images of H, S and V component is as follows:



(a) Original image (b) H component image



(c) S component image (d) V component image
Fig. 3 the images of H,S and V components
For each images, the specific method for calculating the
chromaticity value is
[7]
: n is a assumption that the total
number of image element. The color level of histogram is m
and is a indication which No.i pixel. ( )
1,...,
i
i
c x
=
( )
1
n
u i
i
q c x o
=
u = (

_
(8)
is unit impulse function.
The formula of histogram normalization is as

( )
1,...,
255
min , 255
max
u u
u m
p q
q
=
| |

=
| `
|
\ . )
(9)

The range of values in [0, max(q)] can be normalized to
the interval of [0, 255] based on formula (9) . Then the image
element value of image corresponding to the value of the
histogram for each color can be linked up by back-projection.
That is the greatest probability of Neurosurgery which is
corresponding to the histogram of the pixel, which can be
showed with high brightness. This probability distribution of
the color can be showed in Fig. 3.


(a) Original image (c) H component map

(d)S probability map (e)H probability map

(f) probability map of H ,S,V
Figure3

B) Camshift Tracking
Camshift tracking process is as follows:
(1)Target tracking was selected by hand.
(2)Calculation of a zero moments and first moments:
( )
00
,
x y
Z I x y =
__

n
{ }
1,...,
u
u n
q
=

is the image histogram value of the elements.
Calculation the first moment of X and Y:
970
( )
( )
10
01
,
,
x y
x y
Z xI x y
Z yI x y
=
=
__
__

Here I(x, y) is the image element value of coordinates (x,
y). x and y changes in the scope of the search window.
(3)The calculation of the center of mass for the search
window ( ) ,
c c
x y .

10
00
01
00
c
c
Z
x
Z
Z
y
Z
=
=

(4)The side of the search window (s) that is the function
of a color probability distribution of the former search
window can be re-installed.
(5) Repeating (2)(3)(4) until they are waisted ( the center
of mass is less than the threshold value).
The target of the area in the image is reflected by the
moments. The color probability distribution is discrete gray
image whose maximum is 255, therefore the relation of the
size of installed search window (s) and 255 is

00
2
256
Z
S =
Considering symmetry the odd of the calculated results is
taken close to the S. Through the second moment that is
calculating a gain the long axis, short axis and orientation that
is calculating a gain the long axis and orientation that is
tracked.
Second moment :

( )
( )
( )
2
20
2
02
11
,
,
,
x y
x y
x y
Z x I x y
Z y I x y
Z xyI x y
=
=
=
__
__
__

The Axis angle of the direction goals:

11
00
2 2
20 02
00 00
2
1
arctan
2
c c
c c
Z
x y
Z
z z
x y
Z Z
o
| | | |

|
|
\ .
=
|
| | |
|

| |
\ . \ \ .
|
|
.

2
20
00
11
00
2
02
00
c
c c
c
z
A x
Z
Z
B x y
Z
z
C y
Z
=
=
=

The length of the long axis and short axis in the target of
the image can be calculated by the following:
( ) ( )
2
2
2
A C B A C
L
+ + +
=
( ) ( )
2
2
2
A C B A C
S
+ +
=
When camshaft is used of tracking target in this paper,
the two components of the H , S and V are mainly based.
III. EXPERIMENT
We get through tracking a yellow target of movement to
verify the validity of the algorithm.
Chart (a) is the result of improved algorithm for tracking.
Chart (b) is the result of conventional tracking algorithm.




Chart (a) The result of improved algorithm for tracking




Chart (b) The result of conventional tracking algorithm
The algorithm that can accurately track the moving target
was proved by the experiments of chart a and chart b.
Although traditional algorithms can track moving targets too,
it is worse than improved camshaft algorithm.
971
IV CONCLUSION
In this paper, the camshaft algorithm that based on the
combination of H, S and V space, not only overcome the
traditional camshaft that can only use H space to track the
moving target accuracy shortcomings, but also solve divergent
shortcomings of the traditional camshaft. However this
algorithm is also need to improve such as the tracking miss of
tracking rapid movement background and the target was too
similar to the tracking. These will be addressed in the future
work.
REFERENCES
[1] David Beymer, Philip Mclauch. A Real-time Computer
Vision System for Measuring Tracffic Parameters. 1997 .
[2] Huang Fuzhen, Su Jianbo. Abstracting and tracking of
outline of face based on LevelSet method [J].Computer
transaction, 2003, 26(4), pp: 491-496
[3] W J Rucklidge. Efficiently Locating Objects Using
Hausdorff Distance [J]. International J of Computer
Vision, 1997, 24(3):251-270
[4] Qiu Zhimin, Li Jun, Ge Jun, Zhou Qibo. The research of
automatic object recognizing algorithms based on
Hausdorff distance [J]. Infrared technology, 2006,8(4),pp:
199-202.
[5] Comaniciu D, Meer P. Robust Analysis of Feature Spaces:
Color image segmentation [A]. In: Proceedings of the
IEEE Conference on Computer Vision and Pattern
Recognition CVPR97 [C] , San Juan, Puerto Rico, 1997:
750-755P.
[6] Harrington S. Computer graphics, a programming
approach [M]. New York, USA: McGraw Hill Company,
1987: 376-388P.
[7] Allen John G, Xu Richard Y D, J in Jesse S. Object
tracking using Camshift algorithm and multiple quantized
feature spaces [A]. In: Pan-Sydney Area Workshop on
Visual Information Processing VIP2003 [C], Sydney,
Australia, 2003: 1-5P.

972

You might also like