## 3 The Loitering Detection Methods  
### Target Detection and Tracking  
Loitering detection video is usually shot statically, and the background is changed slowly, mainly considering the impact of illumination, occlusion, and so on. In this paper, in order to achieve the purpose of detecting moving objects, GMM [49] is used to detect the target. The probability density of image gray level is estimated by the gray level difference between target and background, this method has high accuracy and objectivity. Multiple Gaussian models are selected to represent the feature distribution, then compared with the GMM. The EM iterative algorithm is used to solve the parameters of the GMM. Based on the existing library implementation algorithm, some parameter values are default values and complete the classification of target and background. We established \(k\) GMM fusion models in each pixel, the probability density function of a pixel \(X\) at time \(T\) is shown in Equation (1). \[P(X_{t})=\sum_{n=1}^{k}W_{n,t}*\partial\Big{(}X_{t},\mu_{n,t},\sum n,t\Big{)} \tag{1}\]  
where \(W\) is the weight of the Gaussian model, \(\mu\) is the mean vector of the Gaussian model, and \(\sum n\) is the covariance vector of n GMM fusion models. We used the EM algorithm to calculate the parameters of the GMM and posterior probability, set a new latent variable \(Z\), and then transformed Equation (1) by variable \(Z\) to Equation (2). \[P(X_{t})=\sum_{z}p(z)p(x|z)=\sum_{z}\left(\prod_{n=1}^{k}W_{n}*\partial(X,\mu_{ n},\sum n\ )^{zk}\right) \tag{2}\]  
Attain the posterior probability \(\delta(z_{n})\) by the prior probability \(P(z)\), and \(P(x|z)\) is likelihood probability. The posterior probability \(\delta(z_{n})\) is shown in Equation (3). \[\delta(z_{n})=\frac{W_{k}*\partial(x,\mu_{k},\sum k)}{\sum_{n=1}^{k}W_{k}* \partial(x,\mu_{n},\sum n)} \tag{3}\]  
Figure 4: Sector loitering. (**a**) The loitering in the real scene. (**b**) Sector loitering trajectory simulation map. From the Equation (3), the derivative expressions of three variables are shown in Equation (4). \[\pi_{k}=\frac{\sum_{q=1}^{Q}\delta\big{(}z_{q,k}\big{)}}{Q},\mu_{k}=\frac{\sum_{q =1}^{Q}\delta\big{(}z_{q,k}\big{)}x(q)}{Q_{k}},\ \sum k=\frac{\sum_{q=1}^{Q}\delta\big{(}z_{q,k}\big{)}(x(q)-\mu_{k}) (x(q)-\mu_{k})^{T}}{Q_{k}} \tag{4}\]  
where \(Q\) is the number of all the pixels, we update the parameters to convergence by using Equations (3) and (4) so as to achieve the purpose of detecting moving objects; this method has high accuracy and objectivity. After targets are detected, we used the MeanShift method to find the most likely target location in the current video frame [50]. The process of object tracking is to find a target position to make the Bhattacharyya coefficient maximize, it is defined in the following Formula (5). \[\rho=\int\sqrt{p(x)q(x)}dx \tag{5}\]  
\(p(x)\) and \(q(x)\) represent the relative density functions of the discrete position and the target model, respectively. The specific flowchart of target tracking is shown in Figure 5.  
Through the above method, we can track the pedestrian and get a series of tracking coordinates defined in Equation (6). \[s_{i}\ =\{(x_{1},y_{1}),(x_{2},y_{2}),\cdots,(x_{n},y_{n})\} \tag{6}\]  
where \((x_{1},y_{1}),\ \ (x_{2},y_{2}),\ \cdots,\ \ (x_{n},y_{n})\), respectively, represent the position coordinates \((x,y)\) at the corresponding time. Figure 6 shows the motion trajectory. \(s_{i}\) represents the trajectory of the \(i\) target. We use Equation (7) to calculate the change of the pedestrian angle to select the feature points:  
\[\Delta\overrightarrow{v}=arccos\frac{v_{t}*v_{m}}{|v_{t}|*|v_{m}|}>\theta \tag{7}\]  
where \(\Delta\overrightarrow{v}\) represents the direction vector's angle value of the target at the different moment. \(\theta\) is the angle threshold set to \(50^{\circ}\) in our experiment if it meets the condition in the Equation (7) at a point, then we record this point as feature point \(v_{f}\). Figure 5: The scheme of target detection and tracking.