## 3 Methodology
### Computer Vision Module
#### 3.4.2 Tracking Algorithm  
The UAV tracking process is conducted using the PTZ camera once the UAV is detected, automatically adjusting the camera's orientation to keep the UAV continuously located, thanks to the developed algorithm, which is based on three main functions. The first function involves adjusting the camera's zoom to optimize the UAV's size relative to the total image frame. This is achieved by analyzing the percentage of the UAV's area compared to the total area based on the camera's current zoom, as illustrated in Figure 8, and then adjusting the zoom to ensure the UAV has a specified size in the frame. The established value for proper operation is to ensure that the detection area represents between 0.5% and 1.2% of the screen area. If the UAV's area is above or below these threshold values, the camera's zoom is adjusted accordingly. These limits ensure that the UAV is large enough to be detected by YOLOv10 while also being small enough relative to the screen to prevent it from quickly disappearing from the camera's view due to its rapid movements. If the UAV is too large on the screen, it is more likely to move out of the camera's field of view easily. Figure 8: Parameters used for zoom adaptation from UAV detection. Figure 7: Results of the model trained with YOLOv10. The second function is used to calculate the field of view (FoV) of the PTZ camera based on the current zoom level and knowing the camera's specifications. It first establishes a simplified linear relationship between the zoom level (0 to 25) and the focal length (4.8 mm to 120 mm) using Equation (1), which computes the focal length \(f(z)\) from the zoom level \(z\):  
\[f(z)=f_{min}+(f_{max}-f_{min})*\frac{z}{zomm_{max}} \tag{1}\]  
Then, the field of view (FoV) is calculated using the focal length and the camera sensor's size, as shown in Equation (2):  
\[FoV=2*arctan\left(\frac{d}{2*f(z)}\right) \tag{2}\]  
where \(d\) is the sensor dimension representing the horizontal FoV width and the vertical FoV height. The sensor size values are assumed to be 5.7 mm \(\times\) 2.88 mm, based on the manufacturer's information. Finally, the third function calculates the relative movement that the camera must make on the pan and tilt axes to keep the UAV at the center of the camera view. This function is based on trigonometry applied to a circle and its chord, where the chord represents the deviation in the image. The calculation is performed independently for both axes of the screen (horizontal and vertical). First, the camera's FoV is needed from the current zoom level, calculated using the previous function, as the FoV defines the angle of view \((\theta)\) that delimits the chord used in the calculations. To simplify the trigonometric calculations, a circle with a radius of \(r=1\) is used, allowing the chord length to depend only on the angle \(\theta\). Second, it is necessary to calculate the distance from the center of the circle to the chord \(c_{0}\) using Equation (3), as illustrated in Figure 9a. \[c_{0}=cos\left(\frac{\theta}{2}\right)*r \tag{3}\]  
Once this value is known, any deviation of the UAV from the center of the image can be calculated, allowing us to determine \(\alpha\), which represents the angular correction that the camera must apply to center the UAV. The _deviation_ is the difference calculated between the midpoint of the image and the center of the detection on the axis. Figure 9b illustrates how the angular correction is derived from the deviation of the UAV detection from the center, and Equation (4) provides the value:  
\[\alpha=arctan\left(\frac{deviation}{c_{0}}\right) \tag{4}\]  
Figure 9: Representation of the trigonometry used to calculate \(c_{0}\) in (**a**) and _deviation_ in (**b**), where, the black dotted line refers to the centre of the image over the centre of the circle and the purple dotted line to the position where the UAV is located.