Research on tracking method of moving object under the dynamic background

. In order to solve the problem that the traditional moving target tracking algorithm is vulnerable to interference and difficult to accurately track the target for a long time, we first introduce the common target tracking algorithm under the dynamic background, and then we determine the KCF algorithm which has better tracking effect and real-time performance. Then, aiming at the problem of target box offset in the longtime tracking, a tracking algorithm combining Kalman filter algorithm and KCF algorithm is proposed. Finally, the actual effect proves to be effective.


Introduction
Moving target tracking is to use the motion information extracted from target detection to find the position matching with the target features in the continuous frame, and finally obtain the complete motion trajectory of the moving target. The main problems of target tracking include appearance deformation, illumination change, fast motion blur, and so on.

Common tracking algorithms 2.1 Meanshift algorithm
Meanshift algorithm is easily affected by the surrounding environment, such as light and occlusion, which leads to the tracking loss. In addition, when the moving target and background cannot be segmenting accurately, the background will be regarded as the target.

Camshift algorithm
Camshift is an improved algorithm based on Meanshift. The basic idea is to use Meanshift algorithm to find the optimal iteration result for each frame of image in the video, and then take the tracking result of each frame as the initial value of the tracking iteration in the next frame of image, and automatically adjust the window size during the whole tracking process.
Compared with Meanshift algorithm, Camshift algorithm has certain superiority in the direction of moving target tracking, but after tracking for certain time, with large rotational deformation occurs, target information changes, regional matching value becomes higher, and then the target frame changes, which leads to tracking failure.

TLD algorithm
TLD algorithm is a single target tracking method for a long time. It complements and restricts the detection method and tracking method to determine the tracking result together. At the same time, learning module is added to constantly update the sample information, so as to make the tracking effect more stable and reliable. TLD algorithm can be divided into three modules, detection module, tracking module, learning module.

Detection module
Scan the input images through a scanning window, and then determine whether there is a target in each image. A cascade classifier is used to determine whether there is a target in the input image block, which is divided into three parts: variance classifier, ensemble classifier and nearest neighbour classifier. The variance classifier eliminates all image blocks whose grey value variance is less than 50% of the image blocks in the initial tracking box. The grey value variance can be expressed as: The ensemble classifier is composed of independent basic classifiers. Each classifier performs a group pixel comparison on images to generate a binary code. Each classifier has a tree structure, and each tree corresponds to a posterior probability distribution of binary code, which can be expressed as: represents ℎ basic classifier, and respectively represents positive and negative samples corresponding to eigenvalues in the training and updating process. After passing the basic classifier, posterior probability values are generated, and then the integrated classifier identifies the image with an average posterior probability greater than 0.5 as the target. The nearest neighbour classifier calculates the relative similarity of the new sample, . If it is greater than the threshold value, it will be considered as a positive sample.

Tracking module
then calculates the position and scale of the target box in frame + 1 according to the coordinate changes of these points. Wherein, error is defined as: starting from the initial position ( ) at time to track the position ( + ) generating time + , and then reverse tracking from position ( + ) to generate the predicted position ( ) at time , and denote the Euclidean distance between the initial position ( ) and the predicted position ( ) as the error of the tracker at time .

Integrated modules
Tracking module and detection module synchronous running independently, each output forecast target box, can lead to the result is not the only, so comprehensive device first clustering, the results of the detector and then according to the result of detector according to class and tracker tracking results of confidence, for both weighted as the final output, so as to achieve the most tracking effect.

Learning module
Its task is to initialize the detector in the first frame, and then update the detector with learning algorithm in the running process.

KCF algorithm
KCF algorithm, also known as kernel correlation filtering algorithm, is an improved algorithm on the basis of CSK (Exploring the Circulant Structure of Tracking By-Detection with Kernels). KCF algorithm uses the information of the previous image frame and the current image frame to train a target detector in the process of tracking, and then uses the target detector to detect the next frame of image, carries out correlation calculation, and determines whether it is the background or the moving target, and finally updates the target detector with new results. When the target detector is trained, the area where the moving target is selected as the positive sample, and the area around the target is selected as the negative sample. Set the training sample set as( , ), then the linear regression function is: where, is the column vector representing the weight coefficient, which can be solved by the least square method. is the distance between the calculated label ( ) of minimizing the sampled data and the real label of the real target position of the next frame, that is, the more the calculated label resembles the real label, the closer the position of the next frame is found to its real position, where, is used to control the structural complexity of the system, and Equation (5) is converted into matrix form, and the following can be obtained: where, each row of = [ 1 , 2 , . . . , ] represents a vector, is a column vector. If the derivative is equal to 0, we can get: Since it involves calculations in the Fourier domain and involves complex matrices, Equation (5) is transformed into: Because in the KCF algorithm, the target sample gets the training sample of the trainer through cyclic shift, and in the Fourier space, the cyclic matrix has the diagonalization property, namely: where, x represents the value of x vector after Fourier transform, F is the Fourier matrix, and the expression is: In linear problems, the objective function can be substituted into ridge regression equation. However, in reality, most of them are nonlinear problems. At this time, the concept of highdimensional solution and kernel function can be introduced, and the kernel function can be introduced to simplify parameter training. In high-dimensional space, the nonlinear problem can be transformed into a linear problem.
where, ( ) is the function which is mapped to the high space, then the objective function can be expressed as: where, represents the kernel function, defined as follows: The kernel function is introduced to simplify parameter training: where, represents the kernel matrix, and the above equation can be simplified by using the diagonality of the cyclic matrix: where, is the value of the Fourier change of the elements in the matrix.
The new image frame can then be detected by multiplying the correlation and regression coefficients calculated by the filter. KCF algorithm uses the rotation matrix to collect the samples, train the classifier, increase the training samples by translation, and improve the accuracy. The inverse problem of matrix is transformed into discrete Fourier domain, so that the process of inverse matrix is avoided in the algorithm, and the calculation speed of ridge regression is improved. In the aspect of training, the cyclic matrix property is used to train in the frequency domain. In terms of acceleration of kernel regression, the kernel function can also be transformed into the frequency domain for training and detection, which greatly improves the speed. The tracking accuracy and running speed are significantly improved, so that the algorithm can meet the real-time requirements.

Tracking algorithm combining Kalman and KCF algorithm
For KCF target tracking algorithm, in the process of tracking, because the size of the target box is set, once the moving target and the target box drift, if it can't be adjusted in time, it may lead to the continued drift of the target box. Therefore, a tracking algorithm combining Kalman filter algorithm and KCF algorithm is proposed. KCF algorithm is firstly used for target tracking, and then we use the prediction of Kalman filtering algorithm to detect moving target in each frame of the image, and we can determine the movement direction of the moving target, finally we can receive the tracking image and maintain template matching, compare the result of the match and the matching threshold, Then the Kalman filter and moving target template are updated for tracking. The basic idea of Kalman filter algorithm is to realize the mutual iteration of prediction, infer the current state through the previous state, and then update according to the deviation.
Let the state and observation equation of the system be: where, represents the system state at time ; is the state transfer matrix, representing how to predict the current state from the previous state; is the control input matrix, representing how the control quantity is acted on the current state; is the system process noise, and the covariance is .
is the measured value of the system at time; is the observation matrix of the system; is the measurement noise of the system and the covariance is .
Constant prediction, update, re-prediction and re-update in the whole process of Kalman filtering can generally divided into seven steps to complete, with seven formulas to achieve.
The above formula can be divided into three parts. In the first part, Equation (3-2) and Equation  are used to make predictions. Equation (3-4) − 1 is used to calculate the predicted value of the state at time , and Equation (3-5) is used to calculate the predicted value of the covariance corresponding to state vector . In the second part, the gain is calculated using Equation (3)(4)(5)(6). In the third part, Equations (3-7) and (3)(4)(5)(6)(7)(8) are used to update the system state at time . Equation (3-7) is used to calculate the optimal value of the system state at time . Equation (3-7) is used to calculate the covariance corresponding to the optimal result of the system at time .

Comparison between TLD and KCF algorithms
Both TLD and KCF algorithms can track moving targets more accurately. In order to improve the accuracy and real-time performance of the system, this paper uses frame rate per second (FPS) and accuracy as evaluation criteria to compare the two algorithms. The data annotation software LabelImg was used to manually mark the centre point, and the threshold value was set as 20 pixels. The FPS and accuracy of the two were shown in the figures below.

Comparison of KCF algorithm before and improved
It can be seen that the accuracy and FPS of KCF algorithm are higher than that of TLD algorithm, the adoption of KCF algorithm is closer to real-time tracking. By comparing the tracking renderings of the original KCF algorithm and the improved, the tracking effect is significantly improved, the matching degree between the target box and the moving target is better, and the drifting problem is also significantly relieved. Although the average frame rate has decreased, its accuracy rate has increased significantly. Therefore, the tracking algorithm combining Kalman filter and KCF algorithm has better tracking effect.

Summary
In this paper, we mainly compare and analyse the principle and implementation of the four tracking algorithms under the dynamic background. In consideration of tracking effect and real-time performance, the KCF algorithm is finally determined. Then, aiming at the drifting problem of moving target and target frame, a tracking algorithm combining Kalman filter algorithm and KCF algorithm is proposed. Finally, the experimental results prove that it has been improved greatly in the problem of target frame drift.