Research on Improvement of Background Modeling and Detection Method Based on Frame Difference

In order to improve the phenomena such as false edge and void in static background detection of frame difference method and the problems of slow background update and poor adaptability in background difference method, an improved research method based on frame difference background modeling detection method is proposed in this paper. The method first obtains two frame difference images by four frame difference method, carries on the closed operation, and respectively adds with the original image, after adding the two images to carry on the pixel value comparison and the choice, can get the background image. The experimental results show that the algorithm can effectively avoid the appearance of ghost, void and shadow, and adapt to the environment better. Compared with the traditional methods, the algorithm has better real-time performance and higher accuracy.


Introduction
The main task of moving target detection [1][2] is to detect moving targets from image sequences. The motion information of the target in the image can be obtained by detecting the moving target. Moving target detection plays an important role in intelligent transportation, machine vision, aerospace and other fields. The image sequence will be disturbed by various realistic factors, which brings challenges for us to accurately detect moving targets [3].
At present, the more effective target detection methods are mainly optical flow method, inter-frame difference method and background difference method [3].
The optical flow method initializes each pixel in the image sequence into a vector motion field, and performs dynamic analysis according to the velocity vector of each pixel [6]. The optical flow method uses the information of the optical flow field to obtain complete motion information, can better distinguish different moving targets from the background, and can even identify a part of the moving target. The optical flow method has problems such as high time complexity, large amount of calculation, poor real-time performance, and sensitivity to light. The changing light in the environment will be mistakenly identified as optical flow.
The inter-frame difference method often only relies on several adjacent image frames, so it has good stability and can adapt to changes in the environment well. The selection of the inter-frame interval is the key to the inter-frame difference method, which has a great impact on the correct identification of the target. The inter-frame difference method is more sensitive to the influence of noise. The detected  [4].
The background difference method has strict requirements on the background template. The obtained background template does not allow moving targets, otherwise it will cause more noise in the result, and requires the background template to be updated in real time to adapt to changes in the environment. However, in the traditional moving target detection algorithm, the shadow part of the moving target cannot be effectively removed, and the shadow is often detected as a part of the target, resulting in a deviation of the obtained moving target information [3].

Traditional frame difference background modeling and detection method
The inter-frame difference method is a method of performing difference operations on two adjacent frames in a video image sequence to obtain a frame difference image. This method can obtain the contour of a moving target, which is suitable for the situation where there are multiple moving targets. When the moving target in the monitoring scene moves, there will be a more obvious difference between the frame and the frame. The two frames before and after are subtracted to obtain the absolute value of the pixel value of the frame difference image, and then judge by the set threshold. Perform image binarization to determine whether there are moving targets in the image sequence [3]. The inter-frame difference method is usually not used alone in target detection, but is often used in combination with other detection algorithms. The algorithm process is as follows: is the absolute value of the pixel value of the differential image. Binarize the image, the process is as follows: Among them, T is the given threshold, 255 represents the moving target area, and 0 represents the background area.

Background difference method
Since there is a significant difference in the pixel values between the moving object and the background, the current image and the background template can be used to make difference, and then the pixel values of the differential image can be judged by the threshold value. If the pixel value is less than the threshold value, it is set as the background region; otherwise, it is the moving object region [3].
The difficulty of the background difference method lies in the need to construct a standard gray image without moving targets as a background template, and perform the difference processing between image pixel ( , ) i I x y and background image pixel ( , ) back I x y in each frame of the gray image sequence, and then select it based on experience The appropriate threshold of T is judged, and the difference image is binarized, 255 represents the moving target area, and 0 represents the background area, and the grayscale image ( , ) i F x y [7] containing only the moving target is obtained. , In formula (4) and (5), where 1 ( , ) I x y and 2 ( , ) I x y are the pixel values of the first and second frames of the grayscale image sequence, 1,2 ( , ) G x y is the absolute value of the pixel value of the differential image, and 1,2 ( , ) FG x y is the pixel value of the differential image 1,2 ( , ) G x y after binarization.

Figure 2 Difference image after binarization
(2)The second frame of the image is superimposed, and the pixel value of the pixel that has not changed is taken from the original image; otherwise, the pixel value of the pixel is set to 255; , In the formula, 1,2,2 ( , ) I x y is the pixel value after superposition.
(3)In order to avoid overlapping targets and ensure the accuracy of the experimental results, the number of frames can be selected to be farther apart as appropriate. Here, the 211th frame and the 212th frame image are selected for subtraction operation to obtain the difference image, and the threshold value 1  x y is the pixel value of the differential image 211,212 ( , ) G x y after binarization. (4)Overlaid with the 212th frame, the pixel value of the pixel that has not changed is taken from the original image; otherwise, the pixel value of the pixel is set to 255; In the formula, 211,212,212 ( , ) I x y is the pixel value after superposition.
Where is the absolute value of the pixel value subtracted from the background template in each frame of the grayscale image sequence, and is the image after binarization.

Analysis of results
In this experiment, four frames of images are used to carry out the difference calculation, and the pixel value of the difference superimposed image is selected, and a certain pixel value margin is set to preserve the image background pixels as much as possible. Figure 5 is a comparison of the background template obtained by using the traditional frame difference method and the improved method of this experiment. It can be seen from the figure that the background template obtained by the method used in this experiment has no traces of "smearing" and the background pixels Be retained. Figure 6 is a comparison of the results obtained by using the traditional frame difference method and the improved method of this experiment. It can be seen from the figure that the "noise clusters" in the results obtained based on the traditional frame difference method are relatively large because of the background There are reasons for smear in the template. In this experiment, two frames of difference images are used to select pixel values to avoid smear. The experimental results show that the improved method in this experiment can fully satisfy the real-time detection of moving targets in the video sequence.

Conclusion
The experimental results show that the improved method based on the frame difference background modeling detection method proposed in this paper can effectively remove the shadow of the moving target caused by the background difference method, the loss of target information and other shortcomings, as well as the frame difference method. The problems such as smear, holes, target information loss and boundary discontinuity meet the real-time performance and strong robustness. In the Python software, the sample image sequence is detected and recognized for multiple moving targets. The results show that after image processing is performed on the multiple moving target image sequence extracted by the improved frame difference background modeling detection method of this experiment, the multiple moving target image sequences are successfully combined. The moving target was tested and the expected requirements were met.