Research on Traffic Flow Statistics Algorithm Based on Inter-Frame Similarity

Considering some existing shortcomings in traffic flow statistics algorithm based on background subtraction and virtual loop, according to the change discipline of inter-frame similarity while vehicles passing in and out the virtual loop, we come up with a traffic flow statistics algorithm based on inter frame similarity, which is able to overcome two problems: one is missed inspection since some detection targets are close to background color; the other one is repeated detection resulting from over-low speed, then we carry out the experimental results by using the algorithm.


Introduction
With the rapid development of modern economy, the protection of transportation is particularly important, and the requirement for traffic management is getting higher and higher; in order to ensure traffic unimpeded and safe, thus improve the the quality of the environment, it's necessary to use computer science and communication technology in traffic control management and vehicle control.As a result, the intelligent traffic system (ITS), which can promote economic development, is produced conform to the times.Detection technology attained traffic flow in real-time is the basis of ITS.The technology of vehicles detection by using image processing technology to achieve traffic flow detection has become a central issue in the field of research.At present, the incident system in road traffic is divided into loop detection system and video detection system.The loop-type detection system has the characteristics of low price and mature technology, but it has the inherent problems of small amount of detection information, difficulty in installation and maintenance, and easy to be damaged by vehicle extrusion.It is difficult to meet the requirements of long-term stable and accurate detection (Yu, 2002;Yang, 2003).In particular, the main roads in national highway are large amount of traffic flow, complex road conditions, so it would bring considerable difficulties to routine maintenance and repair work of loop-type vehicles after opening the roads.
Therefore, road monitoring should gradually abandon the system of loop-type vehicle detection, and to replace with the video detection system which are superior to loop-type one in performance, cost, life, routine maintenance and system upgrades.However, the first step in implementing this approach is to build a background model.Wren, C.R.(1997)raised a single-Gaussian model; thought the law that appears in the pixels in the background is meeting the single-Gaussian distribution.After that, through carrying out the background modeling by the target area in the video images.Guo, S. & Wang, P. (2016) reduced the background modeling area of each frame, furthermore, compressed the background modeling time, and improved the speed of Gaussian background modeling.Liu, C. W (2012) et al. put forward a background modeling based on time-space video block to achieve vehicle detection well under the condition of foreground contrast.Traffic flow statistics with traditional video detection mainly uses method combining vehicle detection and tracking technology; such as in the technology of vehicle detection.Considering that the correlation of pixels which is the same location on the time and space , Bi, G. L. et al (2015) improve the classical ViBe algorithm, enhance the interference ability of environmental change and extract the prospect goal accurately.Shao, Y. et al (2016) use Gaussian mixture background model to set up the background model, Eliminate noise by Opening operation and complete the extraction of background and foreground by Blob analysis.Ge, L. et al (2014) use Gaussian modeling algorithm to set up the background model, extracted the foreground target by using the background difference method, realize the traffic statistics.Zhang, M. L., & He, X. D. (2016) used CamShift algorithm to realize vehicle tracking, and then completed the traffic statistics by Centroid estimation method.Yang, Y. T. ( 2012) raised a method of video traffic statistics based on fusion of background subtraction method and virtual area to fulfill fast traffic statistics.However, when the color of the vehicle closes to the road, above methods are often unable to get the vehicle's foreground information, resulting in missing inspection.When the speed is too low, it would be repeatedly inspecting the same car and other problems.
Based on the above reasons, this paper raises a traffic flow statistical algorithm with high accuracy and can overcome the problem of vehicle repeated detection caused by missed inspection and over-low speed owing to the body of vehicle closes to road color.First set an area in the video image as a virtual loop.When the vehicle enters or leaves the virtual loop, the similarity of the adjacent image in the virtual loop area will change regularly, and that is the condition that we carry out the traffic flow statistics algorithm based on the inter-frame similarity.

The Basic Idea
In the literature (Yang, Y. T. ,2012) did not take into account the problems such as missed inspection caused by vehicle gray-scale is similar to the road gray-scale, repeated accounting for the same car caused by the speed is too slow, so we introduce inter-frame similarity to improve the above algorithm.First, gray the video image, enhance contrast processing, and set the virtual detection loop in the interested area.Then, using the averaging method for background modeling, setting up virtual loop on the road, next, extract the target vehicle by the background subtraction method, and obtain the black and white graph by dealing the target vehicle area with binarization.Finally, the ratio of the number of white pixels in the black and white graph to the total number of pixels is calculated.When the ratio reaches a threshold, it means that there is at least one vehicle in the virtual loop.We extract he gray-scale image of the virtual loop area of the continuous presence vehicle, use the inter-frame correlation coefficient to present the inter-frame correlation degree, then the correlation coefficient of the adjacent image in the virtual loop is obtained, and the amount of vehicles is counted according to the variation law of the correlation coefficient.As the algorithm is based on inter-frame correlation changes to do the traffic statistics, so it does not rely on the quality of the background, that is to say, it can overcome the problems of missed inspection caused by the gray-scale is similar to road color and the repeated detection caused by vehicle speed is too low.The Algorithm flow chart is as figure 1 follows.

Image Pre-Processing
After graying the colorful video image, the image is subjected to noise reduction using the median filtering method.Then we need to enhance the original gray-scale image to get a better subtraction effect.Because the general image contrast is low, the vehicle area is blurred, the model information can not be prominent apparently, so it is necessary to partly extend the brightness range of the image, enrich the gray level of the image, and thus improve the visual effect of the image to maximize the use of limited gray level, and enhance the useful information in the image.In this paper, according to the principle of non-linear gray-scale transformation, we process the gray images by brightness conversion, in order to achieve the purpose of contrast enhancement.

Background Modeling and Updating
As the background subtraction results can directly reflect the position, size, shape and other information of the moving target, we can get the accurate information of moving target, so in this paper, the background subtraction method is used to detect the moving vehicles.The background subtraction technology mainly depends on the accuracy of the background image, but in the actual production, the background will be influenced by light, shaking of background materials and other factors.
We use the averaging method in background modeling.First of all, in the video image, we take a continuous N frame, calculate the averages of these N frame image pixel gray values, and take it as pixel gray value of the background image.Because the background subtraction method is fast in calculation but sensitive to change in ambient light and some dynamic background changes, we need to update the background in real time.The pixel average is calculated as (Chen, L., 2012): Therein, B x,y is the pixel gray value of the pixel (x, y) in the background model, I k x,y represents the gray value at the pixel (x,y) of the k-th frame video image.

Foreground Target Extraction
The background subtraction method is one of the most commonly used methods in the detection of moving vehicles.It can be regarded as a special inter-frame subtraction method.The basic principle in detection is to subtract the background image which is prepared or real-time obtained from the current image, so as to achieve the detection of the moving target area.If the subtracted value is larger than the threshold set in advance, it is considered to be a moving area, and if the subtracted value is smaller than the threshold set in advance, it is considered to be a background area.This method can be used to determine whether there is at least one vehicle in the virtual loop.Which, the selection of threshold directly affects the accuracy of traffic flow statistics algorithm.
The principle is expressed by the formula (Yang, 2001) as follows: ( , ) ( , ) ( , ) Therein, (x, y) represents the coordinate position in the image, and D k is the result of the subtraction between the kth gray-scale image and the background image in the video, that is, the moving target.F k is the kth gray-scale image in the video, and B is the background image.
And then the moving target D k is binarized.The binarized threshold of D k (x, y) is obtained by using the method of OTSU(Qi, L. N., Zhang, B., & Wang, Z. K. 2006), and then binarized by comparing D k (x, y) with threshold, so we will obtain the result of the binarization W k (x, y) of (x, y) in the kth image.(Wei, S. G. ,2015) The rectangular area on the detection lane in the traffic image is called the virtual loop detection.The width of the loop is less than or equal to one lane, and the height is equal to the height of a car.In the fixed setting, the size and position of the detection area can not be changed after the setting, and the detection area has the presence of the detection loop all the time whatever whether a vehicle through or not.Schematic diagram of the virtual loop on the road is as Figure 2 shows.Virtual loop is the most commonly used detection method in practice.The basic principle is that real-time scans the pixels of the virtual loop, and according to whether there is a moving target in the virtual loop to judge the status of the loop in the image, as well as judge whether there is a vehicle in the current image in line with the change of status of virtual loop, so that the traffic statistics can be carried out.The status judgment formula of the virtual loop is as follows:

The Settings of Virtual Loop
N v is the ratio of the number of white pixels a k in the virtual loop part W k to the total number of pixels W in the virtual loop, N 0 is the threshold for judging whether there is a vehicle or not, and a 0 is threshold of the number of white pixels.s k is the state of the kth virtual loop, s k =0 means that there is no vehicle in the kth virtual loop, and s k =1 represents that there is a vehicle in the virtual loop.

Traffic Flow Statistics Algorithm Based on Inter -Frame Similarity
In reality, the detection environment and moving targets are complex and changeable, and the background subtraction method is difficult to determine the threshold in moving target detection.When the vehicle speed is too low, there will be a situation that repeated account for the same car; when the vehicle body close to the road color, the extraction of vehicle information is limited or even unable to extract, resulting in the situation that can not detect the vehicles.Therefore, based on traffic flow statistics algorithm combining the background subtraction method and virtual loop, we put forward a traffic flow statistics algorithm based on inter-frame similarity, which overcomes the above problems and improves the accuracy of traffic statistics.
The video image has two characteristics, spatial correlation and temporal correlation.Any scene within a single frame of image is composed of several pixels.Thus, a pixel usually has a certain relationship in brightness and chromaticity with some of the pixels around it, which is called spatial correlation; a plot is usually composed of several image sequences, and there is also a certain relationship between the successive two images in one image sequence, which is called temporal correlation.The method of this paper is based on the temporal correlation of the image (Jiang, T. F et al, 2015).This article defines the process of a car into the virtual loop as a plot, as long as statistics out the number of plots according to the temporal correlation, then we can achieve traffic flow statistics.It is known from the experiment that the monotonicity of the inter-frame correlation in the virtual loop is changed when the vehicle enters and leaves the virtual loop, so we detect the inter-frame correlation and achieve the traffic flow statistics.

Calculation of Inter -Frame Similarity
The article uses the relative correlation of adjacent two pictures to represent their inter-frame similarity.In regard to two gray-scale images A(m, n)and B(m, n) ,their matching criterion function can be measured by normalizing the correlation function R ( Zhang, S. Q. et al, 2009) Among them, A is the average value of A , B is the average value of B , the bigger the correlation coefficient between the two pictures, the stronger the correlation between the two pictures.
Figure 3 shows the vehicle enters and leaves within the virtual loop, where the dotted box is the virtual loop, solid line box is the vehicle.It is known from the figure that when a vehicle comes in and out of the virtual loop, the inter-frame similarity in part of the virtual loop becomes bigger then smaller, because the part of vehicle body in virtual loop changes from bigger to smaller.According to this law, we can draw the traffic flow statistics algorithm based on the law of inter-frame similarity changing.
The specific formula is as follows, Among them, C k represents the number of vehicles before the Kth image in the detection area, C 0 =0.Supposing that the current image is the kth image of the detection area, and the correlation coefficient between the kth detection area and the k-1th frame detection area is R k ; the correlation coefficient between the k-1th detection area and the k-2th frame detection area is R k ; -1 ;the correlation coefficient between k-2th detection area and the k-3th detection area is R k-2 .
Because the judgment condition of the vehicle statistics is the law of correlation coefficient changing of the inter-frame virtual loop, the requirement for quality and threshold of the vehicle outlook after the subtraction is not high, it can overcome the problems of missed inspection caused by the similarity between the vehicle foreground and the background gray-scale and repeated counting caused by over-low speed.

Experimental Results
In order to exclude the impact of vehicle followed one by one, error in detection of cart and other factors on the test of the algorithm, we shot a 10-min test video on the pedestrian bridge at the junction of Phoenix North Road and Chaoyang Road in Xiangzhou district, Zhuhai city.The video has a small number of carts, fewer vehicles followed by.Considering all the video images have the problems of large amount of data and the high repetition rate, we use MATLAB to get all the images for batch processing, and select 25 frames / sec video test.

The Results of Background Modeling
After reading all the test images after gray processing, we obtain the image data information.In this paper, we establish the corresponding pixel model through the image of each pixel, and complete the adaptive extraction and update from background.The specific approach is: first sum of all matrices, that is, average 1500 pixels; and then use the median filter, set the gray value of each pixel as the median value of all pixels' gray-scale value with a neighborhood window, and obtain the matrix data corresponding to the image background; finally we use the imadjust function to enhance the background image contrast.In Figure 4, you can see the background images and find out that the effect of background modeling is better.

The Results of Vehicle Information Detection and Extraction
After pre-processing, the target image and the background image carry on the differential operation, and use graythresh function to obtain binarization threshold, the binarization of the results shown in Figure 5.As can be seen from Figure 5, when the vehicle gray-scale is close to the road color, the vehicle information can not be obtained by the background subtraction method.When the vehicle information is incomplete, it has a great impact for statistics algorithm which depends on the foreground information, even causing missed inspection.In fact, the monotonicity of inter-frame correlation coefficient changes during vehicles enters and leaves virtual loop.Therefore, this article uses a trough to represent a plot that a vehicle comes in and out of the virtual loop.According to the video we can see that the traffic flow stops to wait for a red light for a period of time, so in Figure 6 there is a data to keep 1 in inter-frame correlation coefficient.When the green light is on, the traffic flow appears a small vibration with the inter-frame correlation coefficient at the time from stop to slow movement, that is to say, the algorithm that we proposed in this paper has effectively overcome the problems of repeated counting caused by over-low vehicle speed.According to the analysis of Figure 6, it can be seen that the traffic flow statistics algorithm based on inter-frame correlation coefficient is in line with the actual situation.

Analysis of Vehicle Detection Accuracy
> , it represents that a vehicle comes in and out of the virtual loop, that is, the number of vehicles add 1. Then we intercept the kth image, and get the results as Figure 7 shows.It can be seen from Figure 7 that the information of the vehicle is extracted more completely and that the vehicle which is close to the road color, such as black and gray, can be more accurately identified, indicating that the algorithm has higher detection accuracy for vehicles with various colors.

Accuracy Analysis of Traffic Flow Statistics Algorithm
By using the algorithm in this paper to do the traffic flow statistics in the video, we obtain the results as Table 1 shows Table 1.Statistics results of traffic flow the number of vehicles by detecting the number of vehicles realistically accuracy Inter -frame Similarity 70 74 94.59% From Figure 1, it can make a conclusion that the traffic flow statistics algorithm based on inter-frame similarity has a high accuracy, and it can be used to calculate the traffic flow accurately.For one thing, the quality dependence towards background image is relatively lower; for another thing, it provides a new idea for the traffic flow statistics.

Conclusion
At first, this paper introduces the important role of traffic flow counting in the modern intelligent traffic development, and then analyzes the advantages and disadvantages of various traffic flow counting methods.On this basis, we propose the traffic flow detection algorithm based on the inter-frame similarity in the virtual loop.By using MATLAB simulation, analyzing the experimental results, we obtain the algorithm of traffic flow statistics based on the law of inter-frame similarity changing.Because the algorithm only requires the background quality to meet the initial determination of the state of the vehicle in the virtual loop, the dependence on the background quality is not too strong, the algorithm can effectively overcome the problems of missed inspection caused by the similarity between vehicle and the road color close and repeated accounting as speed is too low.In a conclusion, it improved the accuracy of the traffic flow counting effectively.

Figure 1 .
Figure 1.Algorithm flow chart of traffic flow statistics based on inter-frame similarity

Figure 2 .
Figure 2. Schematic diagram of the virtual loop detection line

Figure 3 .
Figure 3. Schematic diagram of the vehicle coming in and out of the virtual loop

Figure 5 .
Figure 5.The results of background subtraction

Figure 7 .
Figure 7. Extraction diagram of vehicle based on inter -frame correlation coefficient C represents the initial number of vehicles, k s is the virtual loop state of the k-th image ( 1 k s = represents the absence of the vehicle), k F is the k-th gray-scale video image, k R is the correlation coefficient of k F and 1 k F − , and k C is the total number of vehicles before the k-th image.