## 3 Methodology
### Computer Vision Module
#### 3.4.3 Localization Algorithm  
The localization of the UAV is performed using fixed cameras. If two or more cameras detect the UAV, they send its exact position to the PTZ camera using an approach based on the intersection of the detection vectors. Figure 10 shows how localization is carried out when two cameras simultaneously detect a UAV.  
Each fixed camera has a \"start direction\", which is the direction in which the camera is oriented. When a UAV is detected, the \"calculated UAV direction\" is computed, indicating the precise orientation of the UAV relative to the camera that detected it. These calculated directions are three-dimensional vectors obtained from the start direction of the camera and its deviation to the central point of the detection box, calculating the deviation angle in terms of pan (horizontal) and tilt (vertical) within a range of 0\({}^{\circ}\) to 360\({}^{\circ}\).  
A non-linear least squares optimization method finds the lines' intersection points representing the fixed cameras' detection directions. The objective function to minimize is the sum of the squared distances from an estimated point in three-dimensional space to each of the lines defined by the detection directions of the cameras. Mathematically, this is represented by Equation (5):  
\[D^{2}=\left\|\vec{r}_{i}-\vec{p}-\left(\frac{(\vec{r}_{i}-\vec{p})*\vec{d}_{i} }{\vec{d}_{i}*\vec{d}_{i}}\right)*\vec{d}_{i}\right\|^{2} \tag{5}\]  
\(\vec{r}_{i}\) is the origin point of camera \(i\), while \(\vec{p}\) is the estimated point in space representing the UAV's position and \(\vec{d}_{i}\) is the detection direction of camera \(i\). This calculation is based on  
Figure 10: Schematic for UAV position estimation using two fixed cameras.  
projecting the estimated point onto each of the lines and measuring the Euclidean distance between the point and its projection.  
Minimization of this function is performed using the Sequential Least Squares Programming (SLSQP) algorithm from the SciPy library. The goal is to find the values of \(x,y,z\) that minimize the following function (6):  
\[\min_{p}\sum_{i}D_{i}^{2} \tag{6}\]  
Once the UAV's position is estimated, the vector connecting the PTZ camera's position to the UAV's position is calculated. This vector is then transformed into pan and tilt units using Equations (7) and (8), which normalize the calculated angles to an appropriate range for controlling the PTZ camera:  
\[pan=\frac{atan2(y,x)}{\pi} \tag{7}\]  
\[tilt=\frac{arcsin(z)}{2\pi} \tag{8}\]  
The innovation in the localization method using fixed cameras lies in its combination of simplicity and precision in determining the UAV's position. Each camera computes the UAV's orientation based on deviations from its initial direction, resulting in three-dimensional vectors. The intersection of these vectors from multiple cameras is then calculated using a non-linear least squares optimization method. This approach minimizes the Euclidean distance between the estimated point and the vectors, ensuring precise localization.  
This method enhances accuracy without requiring complex hardware setups like multiple PTZ cameras. Additionally, it operates in real time and integrates seamlessly with the PTZ camera, directly providing positional data to adjust its focus and tracking. The novelty also lies in its robust mathematical foundation, which employs the SLSQP algorithm, ensuring efficient and accurate computation, even in dynamically changing scenarios.