## 3 System Overview
### ROI Management
#### 3.2.3 ROI Adjustment  
Often the size and shape of the ROI must be adjusted to match the movement of the object inside the ROI. If an object inside the ROI moves toward the camera, the size of the ROI should increase to accommodate the increasing size of the object; the size of the ROI should decrease if an object moves away from the camera. This can be determined by evaluating the optical flow values of ROI subregions. In the proposed system, optical values are calculated for four ROI subregions: the top, bottom, left, and right subregions. Figure 3: Optical flow for ROI displacement. (**a**) Motion vector between subsequent frames. (**b**) Motion vector calculation. The optical values of ROI subregions are compared to adjust the width and height of ROI. Process is shown in Algorithm 1. ``` Initialize:\(MV\_l\gets zero,MV\_r\gets zero,MV\_t\gets zero,MV\_b\gets zero\); \(count\_l\gets zero,count\_r\gets zero,count\_t\gets zero,count\_b \gets zero\); \(OF(x,y)\leftarrow\) optical flow values for all pixels \((x,y)\) inside ROI for each pixels in ROI do if\(x\leq midpoint\) of ROI then if\(OF(x,y)[h]\leq-1\mid OF(x,y)[h]\geq 1\)then \(MV\_l\gets MV\_l+OF(x,y)[h]\) \(count\_l\gets count\_l+1\)  end if if\(y\leq midpoint\) of ROI then if\(OF(x,y)[v]\leq-1\mid\mid OF(x,y)[v]\geq 1\)then \(MV\_t\gets MV\_t+OF(x,y)[v]\) \(count\_t\gets count\_t+1\)  end if else if\(OF(x,y)[v]\leq-1\mid\mid OF(x,y)[v]\geq 1\)then \(MV\_b\gets MV\_b+OF(x,y)[v]\) \(count\_b\gets count\_b+1\)  end if  end if  end if else if\(OF(x,y)[h]\leq-1\mid\mid OF(x,y)[h]\geq 1\)then \(MV\_r\leftarrow MV\_r+OF(x,y)[h]\) \(count\_r\gets count\_r+1\)  end if if\(y\leq midpoint\) of ROI then if\(OF(x,y)[v]\leq-1\mid\mid OF(x,y)[v]\geq 1\)then \(MV\_t\gets MV\_t+OF(x,y)[v]\) \(count\_t\gets count\_t+1\)  end if else if\(OF(x,y)[v]\leq-1\mid\mid OF(x,y)[v]\geq 1\)then \(MV\_b\gets MV\_b+OF(x,y)[v]\) \(count\_b\gets count\_b+1\)  end if  end if  end if if\(count\_l>number\) of pixels in ROI/4 then  Update left bound of ROI  end if if \(count\_r>number\) of pixels in ROI/4 then  Update right bound of ROI  end if if\(count\_b>number\) of pixels in ROI/4 then  Update bottom bound of ROI  end if \(count\_t>number\) of pixels in ROI/4 then  Update top bound of ROI  end if  end if  end if if\(count\_t>number\) of pixels in ROI/4 then  Update left bound of ROI  end if  end if if  end if if\(count\_t>number\) of pixels in ROI/4 then  Update right bound of ROI  end if  end if if  end if if  end if if  end if if  end if



Conclusively, Algorithm 1 describes the overall process of ROI management. First, the variables that manage the boundary of the ROI are initialized. Then, the object bounded by the ROI is tracked by calculating the optical flow values of the pixels inside the ROI. The ROI is divided into two subgroups to analyze the horizontal and vertical boundary movement. The ROI is divided into two subregions, the left and right regions, to check its horizontal boundary adjustment. The optical values of pixels in the left subregion are added up for left-side boundary adjustment. The same applies to the right-side boundary adjustment with the average optical flow value of the right subregion. The top and bottom boundary adjustments are processed in the same way using top and bottom subregions, which are retrieved by dividing the ROI horizontally from the middle. The average optical flow value is calculated by averaging all of the optical flow values that are greater than one or less than minus one. This is to minimize the effect of the background on the UAV motion vector calculated by optical flow values. Since background pixels show minimal movement between frames, pixels with small optical flow values are ignored. In Figure 2b, based on the optical flow values inside the ROI, one could recognize that the background pixels show almost no movement between frames. The accuracy of the algorithm is later evaluated in Section 4.2.