Traffic Flow Detection at Road Intersections Based on K -Means and NURBS Trajectory Clustering

,


Introduction
e perception and prediction of traffic scene mainly includes the acquisition of vehicle flow parameters, the identification of traffic abnormal behavior, and the prediction of traffic congestion status, which is one of the hot areas of traffic scholars in various countries. It is an important task in the traffic scene perception system to obtain the traffic flow parameters in the video sequence. Real-time and accurate vehicle flow parameters can provide important data support for urban traffic control and management organizations. In addition, vehicle flow parameters on urban roads also reflect the current traffic conditions to a certain extent, for example, road traffic congestion status, lane occupancy rate, and road status; these information are conducive to traffic accident early warning, road congestion prediction and automatic planning of travel path [1]. Statistics of the traffic flow information of urban road intersections in different periods and in all directions can also be used as an important basis for the setting of dynamic timing parameters of intersection signal lights. It can effectively improve the traffic efficiency of the road, improve the traffic condition of the urban road network, and bring significant economic benefits to the society [2]. e traffic scene of urban intersection is complex, the vehicle motion mode is changeable, and the occlusion is serious, which make it difficult to detect and track the moving target accurately and continuously. In order to obtain the traffic flow parameters of urban intersections, it is very important to accurately identify the vehicle target and determine its moving direction.
According to the different calculation methods and principles, there are currently four categories of traffic flow statistics: the target detection method [3][4][5][6], feature point motion trajectory clustering method [7][8][9], regional regression method [10,11] and density estimation method [12][13][14]. Seenouvong et al. [3] completed the vehicle count in the set area by combining background subtraction with morphological filtering, with an accuracy of 96%; Memon et al. [4] introduced the Gaussian mixture model (GMM) to quickly detect and count vehicles in the field of view and realized the self-classification of moving targets by contour comparison; Chen [5] proposed to use the B-spline curve method to obtain the vehicle area, so as to realize the vehicle count; Leonel et al. [6] proposed a video sequence vehicle counting method based on augmented quantum space learning. e accuracy rate of counting vehicles at an average speed of 26 frames per second is 96.6%, and it can well deal with camera shake and sudden illumination changes caused by the environment and automatic camera exposure. Rabbouch et al. [7] designed a pattern recognition system based on unsupervised clustering of tracks, which realized intelligent detection, counting, and recognition of traffic targets; Mehboob et al. [8] built a real-time system through analyzing the temporal and spatial characteristics of vehicle trajectory, which it can deduce and track the target behavior online, and joint Hungarian tracking algorithm to count the number of vehicles; in terms of vehicle flow statistics by different types, Rauf et al. [9] proposed a method based on target tracking and convolutional neural network transfer learning; the regional regression method is well reflected in the literature [10,11]. Liang et al. [10] constructed a regression model by extracting the edge features and gradient features of vehicles on the highway to obtain the vehicle flow parameters; Chen [11] suggested a hierarchical classification-based regression model for accurate vehicle counting in view of the complex and changeable characteristics of the actual traffic scene; Lempitsky and Zisserman [12] proposed the target counting algorithm framework based on density estimation in 2010, which is the most common and concerned counting framework at present. e method first generates the truth value image set of the target density distribution by using the target center graph manually annotated. Zhang et al. [13] introduced a vehicle density estimation method based on rank constraint regression and Fully Convolutional Networks (FCN), so as to realize accurate statistics of the number of vehicles. Based on the convolutional neural network (CNN), Sindagi and Patel [14] used deep learning to estimate vehicle density in crowded situations.
In a word, in order to obtain accurate traffic flow parameters, in addition to establishing a reasonable mathematical model, it is particularly important to generate features that can truly reflect the running status of vehicle targets. However, the scene of urban intersection is complex, the moving state of the target is changeable, there are many occlusions, and rich target feature information is needed. e target trajectory can provide a wealth of spatiotemporal data such as direction and speed, and it has good stability in all-weather operation. is manuscript takes the trajectory of vehicle as an important feature, firstly, NURBS is used to fit the trajectory curve; then, k-means algorithm is used to complete the clustering of the trajectory curve; finally, based on the clustering results, the short-term traffic flow in each region and direction of the intersection is predicted.

K-Means Trajectory Clustering Based on NURBS Curve Fitting
Trajectory clustering is to use the appropriate similarity measurement method to complete the best classification of the obtained trajectory features. To explore suitable similarity measurement criteria to ensure the best clustering results, we choose K-means clustering algorithm, which has fast calculation speed and high efficiency and is suitable for finding convex shape clusters. Aiming at the defects of the randomness of initial mean and the sensitivity of noise outliers, this manuscript introduces NURBS curve fitting to solve the problem of noise points when the target pairs to form a trajectory. e NURBS curve can be regarded as the sum of the product of a series of control points V i (i � 0, 1, 2, . . . , n) and the base function N i,k (u) determined by the known node sequence u i , (i � 0, 1, 2, . . . , n). Combined with a series of weight factors that can affect the shape of the curve, the mathematical expression of the vector function is as follows: . (1) In the formula, B i,k (u) is the basis function of the k-th normal B-spline; d i is the control vertex, also known as the De Boor point; ω i is the weight factor; and u is the parameter value. e weight factor introduced by the NURBS function can realize the local correction of curve flexibly. Before the kmeans algorithm clusters the trajectory, first, our method fits the NURBS curve through B-spline quadratic interpolation and, then, calculates the first-order guide vector of all the trajectory points, which is equal to the tangent slope passing through the point in 2D plane. If the curve is smooth and continuous, then the tangent slopes of all trace points on the curve will change between the slopes of the two control points; otherwise, it indicates that there are irregular points on the curve. According to the nearest point search algorithm of k-d Tree [15], all irregular points can be found by traversing the whole trajectory, and the best trajectory can be obtained by NURBS curve fitting again.

NURBS Curve Fitting of Track Points.
Based on detection results of vehicles, their track matching was used to eliminate irregular measurement points by the piecewise straightline fitting method. However, the trajectory fitted by this method is not smooth, and there are many inflexion points; secondly, due to the influence of perspective projection transformation of image, the position of many points has been distorted, so it is unable to predict the macromotion trajectory of the vehicle intuitively. In this paper, the NURBS function in the theory of curve geometry [16], is applied to the fitting of vehicle trajectory. It has good invariance to perspective projection transformation. It can effectively eliminate irregular points, improve the representation ability of trajectory, and ensure that the traffic flow at intersections can be accurately predicted through the processing of the trajectory subregion and subdirection. e essence of NURBS curve fitting based on trajectory points is to interpolate or fit the measurement points into smooth curves. e trajectory curve fitting steps are as follows: (2) e NURBS curve is fitted by the interpolation function to the measuring points: Among them, P i is the type value point, the parameter u k corresponding to measurement point B k is calculated by the chord length parameterization method, and the node vector U is determined by the mean value method. In this way, after the basis function is found, it is substituted with the type value point into the following formula for calculation: After that, a system of equations with the point P i as an unknown is obtained, and it is composed of n + 1 equations but n + 3 unknowns, belonging to the overdetermined system of equations with no linear solution, so we need to establish other two equations to solve it. Considering the particularity of the first and end points, the mathematical relationship between the first-order derivative vector D 0 , D n and the adjacent type value points P 0 , P 1 and P n− 1 , P n is as follows: Combining equations (5) and (6) with equation (3), a system of linear equations whose coefficient matrix is (n + 3) * (n + 3) is obtained, and then, we can solve this system and get the 2D coordinates of n + 3 control points. en, the NURBS curve is fitted with a nonrational quadratic B-spline interpolation function, and the derivative of the vector is obtained at any point as follows: Among them, P j− 1 , P j , and P j+1 are three adjacent measurement points in the NURBS curve, and the parameter

K-Means Trajectory Clustering.
ere is a big deviation in the k-means algorithm due to the uncertainty of the initial clustering center. In our manuscript, the minimum distance is proposed as a measurement criterion to select the initial clustering center. In view of the fact that the start and end points of each moving vehicle's trajectory at the intersection must be clustered in each intersection area, it is accurate and simple to predict the trajectory trend with them. All the vehicle's movement trajectories obtained by fitting NURBS are represented by sets P start and P end of start and end points. We calculate the normalized Euclidian distance between any two points in set P start and P end ; find the samples with the shortest distance by the quicksort method and write it as P d0 and P dn ; calculate the Euclidean distance between them and residual sample points in the set P start and P end ; find out the sample points with the smallest distance from the center of P d0 and P dn ; increase them to P d0 and P dn , and repeat this process until we have k sets of objects. Finally, k object sets are averaged numerically to form a group of clustering centers, which are used as the initial clustering centers when k-means algorithm is used to complete the trajectories clustering, and k clustering centers J k are obtained. e centroid is taken as the central location of the intersection J e , and k is equal to the number of intersection areas.
Calculating the direction angle θ k and θ k ′ of motion of the points P start and P end , the vehicle's movement pattern can be known by judging their respective regions. Assuming that θ k belongs to zone A and θ k ′ belongs to zone C, it is believed that there are vehicles in the direction from A to C. After traversing all the trajectories, traffic flow prediction results in each direction of the classification vehicle can be obtained. Vehicle types can also be obtained based on vehicle target detection technology, so each vehicle trajectory can be marked with category, so that the flow parameters of different types in each region can be counted.

Experiment and Result Analysis
e experiment only counts the vehicle flow. Based on the statistical data, more traffic flow parameters such as queue length and road proportion can be calculated. ree different intersection scenes including morning and evening rush hours are selected for experiments about 7 days, and the characteristics of experimental data are shown in Table 1.
For each scene, intersection partitions were obtained by combining k-means trajectory clustering through NURBS curve fitting, and vehicle trajectories in all directions were statistically analyzed to obtain specific results of vehicle flow prediction of different types. Figure 1 is the vehicle statistical results of each intersection scene on a certain day by region using our system. Figure 2 is the traffic flow of the scene separately counted every day. Tables 2-4 are the comparison over 7 days between the average results obtained by our algorithm and the manual statistical results based on the absolute error. Among  them, N E is the experimental value and N T is the manual monitoring value.
e experimental results show that the statistical error of traffic flow is small, no matter for the T-junction or the intersection, and the maximum error is less than 10% and it can meet the needs of intelligent transportation applications. In view of the traffic condition unblocked scene, the target is shielded less, and the relative accuracy is slightly higher. For the scene of intersection, the vehicle target has more occlusion, the trajectory caused by it has fault discontinuity, which is effectively bridged through adoption of NURBS curve fitting to irregular points. erefore, the vehicle flow error of k-means trajectory clustering statistics is much lower than that of the singlelane or multilane statistical method, and the new idea effectively solves the problems of incomplete tracking trajectory and complex calculations.

Conclusions
e real-time and accurate parameters of traffic flow at urban road intersections are the important basis for setting dynamic timing parameters of traffic signals at intersections. is paper mainly studies the vehicle flow counting method at urban intersections based on vehicle trajectory analysis. On the basis of the traditional method to obtain the tracking trajectory, the smooth track curve is fitted based on the NURBS algorithm, and a minimum distance measurement criterion is designed to select the initial clustering center for improving the k-means trajectory clustering method, then through subordinating the first and end points of the track to the intersection area, the vehicle movement mode is determined, and the traffic flow statistics of each area at the intersection are realized. Experimental results show that the method effectively solves the changeable mode and severe occlusion of moving vehicle problems, under the complex scene at the intersection, traffic statistical error is less than the classical method, and the algorithm is simple and can provide reliable data automatically for the traffic accident warning, road congestion prediction, and route planning.

Data Availability
e data used to support the findings of this study are available from the corresponding author upon request.