## 2 Material and Method
### Approach of Citrus Tracking and Counting Based on YOLOv7-Tiny and DeepSORT
#### 2.3.2 DeepSORT-Based Citrus Fruit Tracking  
The YOLOv7-tiny deep learning model is used to extract the visual features of the targets such that each target has a unique representation in the feature space. Then the DeepSORT [22] serialization optimization algorithm, specifically the SORT (simple online and realtime tracking) algorithm based on the Kalman filter and the Hungarian algorithm is used to achieve the tracking of citrus fruits and maintain the stability and accuracy of tracking. 1. Fruit target prediction based on the Kalman filter algorithm  
Kalman filtering (KF) is a recursive filtering method for estimating the state of a system and is commonly used in linear systems in areas such as signal processing, control systems, and target tracking [23,24]. Since the video frame rate of the citrus fruits acquired in this paper is 30 frames/s, the position of citrus fruits varies very little between video sequences (which can be basically regarded as a uniform motion) and it can be assumed that the citrus fruit tracking system is linearly correlated over time. In the prediction phase, the Kalman filter predicts the corresponding citrus tracking position and its covariance matrix based on the detected position of the YOLOv7-tiny network. \[\hat{x}_{k|k-1}=A\hat{x}_{k-1|k-1}+Bu_{k-1} \tag{1}\]  
\[P_{k|k-1}=AP_{k-1|k-1}A^{T}+Q \tag{2}\]  
Figure 3: Overall flow chart of citrus tracking and counting method. where \(\hat{x}_{k|k-1}\) is the a priori state estimate of the \(k\)th frame, which is the result of the intermediate computation of filtering, i.e., the result of the kth frame predicted based on the optimal estimate of the previous frame (\(k-1\) frame), and the result of the prediction equation; \(A\) and \(B\) are the parameter matrices of the system; \(\hat{x}_{k-1|k-1}\) is the a posteriori state estimate for the \(k-1\) frame, which is one of the results of the filtering; \(u_{k-1}\) is the process noise at frame \(k-1\); \(P_{k|k-1}\) is the a priori estimated covariance at frame \(k\), which represents the uncertainty of the state and is one of the results of the filtering; and \(Q\) is the covariance of the system's process noise, which is the state variable used by the Kalman filter for estimating the discrete-time process. In the update phase, the Kalman filter optimizes the predicted values obtained in the prediction phase using observations of the current frame to obtain a more accurate new estimate, i.e., updating the fruit tracking position and its covariance matrix based on the matching relationship between the detected and predicted fruits. \[K_{k}=P_{k|k-1}H^{T}\Big{(}HP_{k|k-1}H^{T}+R\Big{)}^{-1} \tag{3}\]  
\[\hat{x}_{k|k}=\hat{x}_{k|k-1}+K_{k}\Big{(}Z_{k}-H\hat{x}_{k|k-1}\Big{)} \tag{4}\]  
\[P_{k|k}=(I-K_{k}H)P_{k|k-1} \tag{5}\]  
where \(K_{k}\) is the filter gain matrix, which is the intermediate calculation of the filter; \(H\) is the state variable to observation variable conversion matrix, which represents the relationship connecting state and observation. \(R\) is the measurement noise covariance; \(\hat{x}_{k|k}\) is the number of frames in the \(k\) frame of the a posteriori state estimate, which is one of the results of the filtering; \(Z_{k}\) is the measurement value, which is an input to the filtering; \(P_{k|k}\) is the a posteriori estimated covariance of the \(k\) frame's a posteriori estimated covariance, which is one of the results of the filtering; \(I\) is the unit matrix. 2. Fruit Target Matching Based on the Hungarian Algorithm  
The Hungarian algorithm is a combinatorial optimization algorithm for solving the task allocation problem in polynomial time [25]. In this paper, after obtaining the video detection results and the prediction results in the citrus video, the Euclidean distance is used to measure the similarity between the Kalman filtered prediction results and the YOLOv7-tiny detection results.