# Toward Scalable Video Analytics Using Compressed-Domain Features at the Edge
## 3 Methodology
### Light-Weight Runtime Moving Object Detection in the Video Compressed-Domain
#### 3.2.1 Median Filter and Moving Object Detection  
Compressed-domain MVs may not represent the actual true motion due to the properties of motion estimation, biased towards efficient coding, as shown in Figure 8a,e. Therefore, it is desirable to eliminate motion vectors that can be categorized as unsuitable for moving object detection. We assume that MVs whose magnitudes are very high or very low, compared to the other MVs related to the moving object, have to be replaced with the median value of neighboring MVs. Therefore, the application of the vector median filter aims to reduce isolated vector noises and smoothen the difference of MV between adjacent blocks. Note that the sliding window approach is used for median filtering. Because H.264/AVC allows for variable-sized block partitioning, we construct a uniformly sampled MV field by mapping all MVs to 4 \(\times\) 4 blocks. Theoretically, the motion vector average (normalized vector) among all elements \(N_{mv}\) in the \(N\)\(\times\)\(N\) (\(N\) = 4 in this study) window function is calculated by Equation (1):  
\[N_{mv}=\frac{\sum_{i=1,j=1}^{N\times N}MV_{ij}}{N\times N} \tag{1}\]  
where \(MV_{ij}\) is the MV elements in the \(N\)\(\times\)\(N\) window. Finally, the smoothened motion filter is presented, which is experimentally determined as shown in Figure 8b,f using the input MV, including isolated motion vector noise, smoothened in the areas that mostly correspond to the object boundaries. In order to detect the moving objects, a cluster detector is involved to determine the number of moving objects and their approximate positions in the scene. Then, a density-based cluster technique is applied to completely segment moving objects. The first step involves MVs whose magnitudes can be used to easily differentiate moving objects from the stationary background. However, it is difficult to directly and completely segment moving objects because not all MVs on the objects have the same motion state. While every part of a rigid body maintains nearly the same motion state, different parts of a non-rigid body can move in various ways (see Figure 9). In order to cluster detected MVs into dynamic clusters, a range search algorithm based on the euclidean distance of the MV point is used, under the presumption that dense points represent the same object. This requires a parameter \(\epsilon\) where \(\epsilon\) is the spatial distance threshold between density reachable MV. The goal is to partition \(n\) MV points \(\chi\subset\mathbb{R}^{d}\) into \(k\) clusters using the k-means filter. Each of the \(n\) data points will be assigned to a cluster with the nearest mean. The mean of each cluster is called its \"center\". For the k-means problem, we wish to choose \(k\) centers \(\mathbb{C}\) so as to minimize the potential Equation (2):  
Figure 7: Video coding motion vector extraction from consecutive frames with two video test sequences. (**a–c**) our recorded video; (**d–f**) test video in VIRAT. \[\phi=\sum_{x\in\chi}\min_{c\in\mathbb{C}}\|x-c\|^{2} \tag{2}\]  
From these centers, we can define a clustering by grouping data points according to which center each point is assigned. With MV points, the following steps are performed frame by frame:  
* For each \(p_{i}\in\chi\), find all the neighboring points within spatial distance \(\varepsilon\). * Cluster all the MV points that are density reachable or density connecting [39] and label them. * Terminate the process after all the MV points are checked. The output is a set of clusters of dynamic points. The distance threshold \(\varepsilon\) decides the range of density reachability [39]. After this process, the label list includes the moving objects and certain big MVs' noises, as shown in Figure 8c,d. To eliminate these noises, we based the observation on the fact that noise motions because of lighting condition changes usually randomly occur without following a certain flow. Therefore, the tracking motion's trajectories' length is then used to classify the detected motion into the real motion or noise group.