## 2 Materials and Methods
### Tracking Method
#### 2.5.2 Camera Motion Compensation  
Tracking methods based on detection largely depend on associating predicted target positions with the detected bounding boxes. However, due to certain objective factors, such as camera shake or slight shifts caused by wind, there can be displacement in the detection boxes, leading to switches in the target IDs. This study employed a camera motion compensation method to address this issue to improve the algorithm. Drawing from the global motion compensation (GMC) technique used in the video stabilization module with affine transformation proposed by OpenCV [17], a camera motion compensation approach was designed. This image registration method is particularly suited for scenes with significant background shifts.  
The process begins with extracting key points and feature tracking using sparse optical flow. The affine matrix is then solved using RANSAC [18]. By utilizing sparse registration techniques, it is possible to ignore other moving objects in the scene, thus more accurately determining the background. This method enhances the stability and accuracy of object tracking by compensating for camera motion, thereby minimizing the risk of incorrect target ID assignments due to background displacement. It is a critical improvement for ensuring the robustness of the detection and tracking systems, especially in outdoor environments where camera movement is more likely.  
To transform the predicted bounding boxes from frame k-1 to the coordinates of the next frame using the affine matrix \(A_{\text{k-1}}^{k}\), the specific calculation method shown below was used:  
\[A_{\text{k-1}}^{k}=[M_{2x2}|T_{2x1}]=\begin{bmatrix}a_{11}&a_{12}&a_{13}\\ a_{21}&a_{22}&a_{23}\end{bmatrix} \tag{4}\]  
In this context, \(M\in R^{2x2}\) is a matrix that includes the affine matrix \(A\), as well as the scale and rotation components, while \(T\) is a matrix that contains the translation component,  
\[\widetilde{M}_{K-1}^{K}=\begin{bmatrix}M&0&0&0\\ 0&M&0&0\\ 0&0&M&0\\ 0&0&0&M\end{bmatrix},\widetilde{T}_{K-1}^{K}=\begin{bmatrix}a_{13}\\ a_{23}\\ 0\\ 0\\ \vdots\\ 0\end{bmatrix} \tag{5}\]  
Here, two matrix parameters, \(\widetilde{M}_{k-1}^{k}\in R^{8\times 8}\) and \(\widetilde{T}_{k-1}^{k}\in R^{8}\), are defined to control the translation and rotation transformations of the image.  
\[\hat{x}_{k|k-1}^{\prime}=\widetilde{M}_{k-1}^{k}\hat{x}_{k|k-1}+\widetilde{T} _{k-1}^{k} \tag{6}\]  
\[P^{\prime}_{k|k-1}=\widetilde{M}_{k-1}^{k}P_{k|k-1}\widetilde{M}_{k-1}^{k^{ \intercal}} \tag{7}\]  
where \(\hat{x}_{k|k-1}\) and \(\hat{x}_{k|k-1}^{\prime}\) denote the predicted state vectors of the Kalman filter at k moments before and after camera motion compensation, and \(P_{k|k-1}\) and \(P^{\prime}_{k|k-1}\) denote the covariance matrices of the Kalman filter before and after correction, respectively. Subsequently, this study used \(\hat{x}_{k|k-1}^{\prime}\) and \(P^{\prime}_{k|k-1}\) in the Kalman filter state update process as follows:  
\[K_{k}=P^{\prime}_{k|k-1}H_{k}^{\intercal}(H_{k}P^{\prime}_{k|k-1}H_{k}^{ \intercal}+R_{k})^{-1} \tag{8}\]  
\[\hat{x}_{k|k}=\hat{x}_{k|k-1}^{\prime}+K_{k}(z_{k}-H_{k}\hat{x}_{k|k-1}^{ \prime}) \tag{9}\]  
\[P_{k|k}=(I-K_{k}H_{k})P^{\prime}_{k|k-1} \tag{10}\]  
In the case of high-speed target motion, the correction of the state vector, including the velocity term, is essential. When the camera offset changes slowly relative to the targetframe rate, the correction of Equation (4) can be omitted. This correction method makes the proposed tracker more robust against camera offsets.