## 3 System Overview
### ROI Management
#### 3.2.2 ROI Tracking  
The proposed system adopts optical flow to manage the movement of ROI for the frames that were not used by UAV detection. Figure 2b demonstrates the information that results from optical flow calculation, and Figure 3 depicts how optical flow is adopted to calculate the motion vector of ROI in the proposed system. When an object shown in a video moves between frames, the motion vector of the object between two frames can be calculated using optical flow. In Figure 3a, motion vector \(v\) refers to the movement of a square object. The proposed system calculates the motion vector \(v\) using optical flow  
Figure 2: ROI management effect. (**a**) ROI classification using UAV detection. (**b**) ROI tracking using optical flow.  
values. Figure 3b depicts the optical flow values of pixels inside a particular area. Optical flow calculation produces motion vectors of pixels, as shown in the figure. Figure 2b shows an example of optical flow values extracted from a video. The figures imply that the optical flow values of the UAV area are consistent, and the UAV's motion vector can be calculated. The motion vector of ROI is the average of the optical flow values of pixels in the ROI. The proposed system estimates the displacement that needs to be applied to the ROI to contain the important content inside it by utilizing optical flow values of the ROI. Thus, the movement of UAVs can be tracked, and the ROI can be adjusted according to it.  
The proposed system only calculates the optical flow of the pixels inside the ROI to minimize calculation. Calculation of optical flow over such region returns optical flow values of every pixel in the ROI. However, simply averaging the optical flow values does not produce an accurate motion vector of the ROI. The ROI will not only contain UAVs, but the backgrounds, too. The portion of background in the ROI is not negligible. Therefore, optical flow values of the background pixels will count as errors and hinder the accuracy of the resulting motion vector. Thus, when the proposed system calculates the motion vector of the ROI, it ignores the optical flow values of the background by ignoring the optical flow values close to zero. However, errors by optical flow values of the background can be accumulated. Thus, updating the ROI based on the UAV detector is essential for accurate ROI tracking. The displacement of the ROI can be formulated as the following equation:  
\[\begin{split} v_{x}=\overline{OF_{x}},\quad\text{where}\;OF_{x} =\{\forall\|OF(x,y)_{x}\|>t\},\\ v_{y}=\overline{OF_{y}},\quad\text{where}\;OF_{y}=\{\forall\|OF(x, y)_{y}\|>t\}.\end{split} \tag{1}\]  
In Equation (1), \(v_{x}\) and \(v_{y}\) represent the displacement of ROI in the x-axis and y-axis, respectively; \(OF(x,y)_{x}\) and \(OF(x,y)_{y}\) represent the horizontal and vertical component of optical flow value at \((x,y)\); and \(t\) is the previously set threshold value. This equation calculates the mean of the movement of valid pixels inside ROI. With Equation (1), the proposed system estimates the area of the UAV on a frame without using the UAV detection algorithm on every frame by utilizing optical flow.