# Efficient Crowd Anomaly Detection Using Sparse Feature Tracking and Neural Network
## 3 Materials and Methods
### Crowd Representation and Behaviour Descriptors
#### 3.1.2 Sparse Feature Tracking  
Sparse feature tracking is an efficient technique used in computer vision to track a subset of features spanning in video frames. It addresses challenges such as occlusion and changes in crowd dynamics by focusing on tracking distinctive features within the crowd, making it less susceptible to occlusion and environmental changes compared to dense tracking methods. By selecting key points of interest, sparse feature tracking can maintain robustness in tracking even when parts of the crowd are occluded or when there are dynamic changes in crowd movement. Additionally, sparse feature tracking algorithms often incorporate mechanisms for feature re-detection and association, allowing them to adapt to changes in crowd dynamics and maintain accurate tracking over time. This method utilises the most prominent features that are easy to track, such as the corners or any unique structures in the frames. Our approach is based on the local features explained above. The Lucas-Kanade approach [35] is employed to address the issue of an unrestricted optical flow. The Lucas-Kanade optical flow approach excels in crowd anomaly detection due to its accuracy, robustness, and adaptability to complex scenarios. By focusing on sparse feature tracking, it reduces the computational complexity while maintaining high tracking accuracy, making it suitable for real-time applications. Its ability to capture subtle motion variations within crowded scenes enables the detection of anomalous behaviours amidst complex crowd interactions. Leveraging temporal coherence ensures stability in feature tracking and reduces false positives, enhancing the reliability of anomaly detection. Overall, the Lucas-Kanade optical flow approach offers a simple, efficient, and effective solution for crowd anomaly detection in diverse surveillance and monitoring applications. This method anticipates that all neighbouring pixels within a highly restricted region will exhibit identical optical flow values. The optical flow is calculated using this group of pixels, in contrast to other optical flow algorithms, which utilise all pixels in the frame. Sparse optical flow offers several benefits, including faster computation and the rapid generation of training data. The optical flow constraint for a group of pixels moving at the same velocity can be mathematically represented as in Equation (2):  
\[\begin{split} I_{x}(x_{1},y_{1})\cdot v_{x}+I_{y}(x_{1},y_{1}) \cdot v_{y}&=-I_{t}(x_{1},y_{1})\\ I_{x}(x_{2},y_{2})\cdot v_{x}+I_{y}(x_{2},y_{2})\cdot v_{y}& =-I_{t}(x_{2},y_{2})\\ &\ldots\\ I_{x}(x_{n},y_{n})\cdot v_{x}+I_{y}(x_{n},y_{n})\cdot v_{y}& =-I_{t}(x_{n},y_{n})\end{split} \tag{2}\]  
The above Equation (2) can be reformulated using matrix vector notation as represented in Equation (3):  
\[\left(\begin{array}{cc}I_{x}(x_{1},y_{1})&I_{y}(x_{1},y_{1})\\ I_{x}(x_{2},y_{2})&I_{y}(x_{2},y_{2})\\ I_{x}(x_{n},y_{n})&I_{y}(x_{n},y_{n})\end{array}\right)\cdot\left(\begin{array} []{c}v_{x}\\ v_{y}\end{array}\right)=-\left(\begin{array}{c}I_{t}(x_{1},y_{1})\\ I_{t}(x_{2},y_{2})\\ I_{t}(x_{n},y_{n})\end{array}\right) \tag{3}\]  
Considering that this system usually presents more equations than variables, it is frequently over-determined. The Lucas-Kanade method applies the least squares technique to address this, thus finding a balanced solution. As a result, it offers a solution to the system, as illustrated below in Equation (4):  
\[\begin{split} A^{T}Av=A^{T}b\\ v=\left(A^{T}A\right)^{-1}A^{T}b\end{split} \tag{4}\]  
The Lucas-Kanade method [36], which was primarily developed for local optimisation, may perform poorly with severe object motion due to its reliance on neighbouring pixels for gradient determination. To address this, a pyramidal structure is utilised, using a coarse-to-fine technique in which the input images are down-sampled, first with a low-pass filter and then by a factor of 2 [35]. The optical flow computation begins with the lowest-quality images and proceeds to higher resolutions, improving the flow field's accuracy.