# Ball Tracking Based on Multiscale Feature Enhancement and Cooperative Trajectory Matching
## 3 Methods
### Ball Tracking
#### 3.4.2 Automatic Trajectory Correction  
Automatic trajectory correction aims to provide a more stable tracking trajectory in an online and lower-cost form, and it always tends to retain more detection to form a longer trajectory. Multilevel collaborative matching processing can produce sufficiently accurate ball-tracking trajectories when the accuracy of ball detection is relatively high. However, in most cases, due to complex sports scenes, the results of ball detection are not reliable enough, so additional processing is required. Automatic trajectory correction improves the accuracy of the trajectory, thereby enhancing the performance of motion behavior analysis. Trajectory analysis. There are several forms that a trajectory segment that has not undergone automatic trajectory correction may be in. Among them, Figure 4a represents a complete and smooth trajectory, which is the ideal state. At this time, each detection represents the state of the ball at a certain moment to the greatest extent possible. No correction processing is required. Figure 4b represents that part of the detection is missing in a section of the trajectory, causing the trajectory to be interrupted. For example, the ball is blocked by a player. In this case, only interpolation is needed based on the position of the missing frame. Figure 4c represents a small amount of misdetection in a section of the trajectory, but it does not affect the main body of the movement trajectory. This kind of situation often occurs when the image quality is poor, and the player part is extremely similar to the ball. In view of this, such situations need to be corrected based on the before and after detection results of false detection. Figure 4d represents a relatively drastic change in the spatial position of the ball during this time period, resulting in two far-apart trajectory segments. The possible reason is that the ball flew out of the screen at this time or the camera switched. For this kind of situation, you only need to handle the boundary between the two fragments before and after. Figure 4e represents the extreme case of case Figure 4c. When there are no balls in the picture for a long time, a large number of false detections cause the trajectory segments to become very messy, and any subset composed of detection cannot meet the requirements of forming a smooth trajectory, i.e., a minimum threshold, so these illegal detections need to be discarded until new trajectory segments appear. Trajectory correction algorithm. Automatic trajectory correction adopts the idea of sliding windows and the form of a finite state machine (FSM) [37] to handle the above situations automatically. Finite state machines can be divided into three states, showed as Figure 5. The search state is used to find the left boundary of a suitable sliding window. If found, a sliding window can be constructed and entered into the candidate state for verification processing. Otherwise, the left pointer will be moved until it is found or reaches the end. The candidate state is to check whether the detection set in the current window can extend the ball trajectory. Trajectory fragments may both extend the old trajectory and serve as a new beginning. Extending the old trajectory as much as possible can reduce the number of trajectory segments and improve the overall stability of tracking. The repair state is to repair the deviation detection in the window according to the simple linear motion model or to interpolate the missing detection to improve the tracking accuracy as much as possible. Candidate states look for the most promising detection within the window. Use Equation (21) to determine whether detection i and detection j satisfy a linear relationship.