# Shooting Prediction Based on Vision Sensors and Trajectory Learning
## 3 Basketball Movement Trajectory Acquisition and Shooting Prediction Method
### Real-Time Position Acquisition during Basketball Movement  
When using the image registration technology to determine the initial position of the basketball, the image to be searched is cut out from the first frame of image, so the initial position is relatively accurate. However, since the position of the basketball and the color and shape features of the images of the second frame and later are constantly  
Figure 3: The searched image and the searched target.  
changing, it is difficult to obtain the exact position of the target basketball when the same template is used to continue matching. First, keep the accurate position of the basketball in the first frame image and use it as the reference position. Then, by analyzing the color and shape characteristics of the basketball, using the large difference between the basketball color and the background, and using the RGB components to effectively remove the background interference, multiple areas containing the basketball are obtained. The position of the basketball can be determined through further operations, and the process is shown in Figure 4.  
The RGB value refers to the brightness value that divides the three colors of red, green and blue into 256 levels, and the objects in each color image have different color characteristic RGB components. Since the red channel features of the basketball are the most obvious in the video images collected in this paper, by constructing the red channel, the interference of the sky, trees, ground, and testers can be eliminated, while most of the characteristics of the basketball and objects similar to the basketball can be retained. However, there are still some small interferences in the processed images, which are eliminated by the open operation [20]. For the image A and the target S, use A + S to express the use of S to dilate A, and use A - S to express the use of S to erode A, then the open operation relation of the image is as shown in (5) [21].  
\[A\circ E=(A-E)+E \tag{5}\]  
The image after background removal and opening operation is shown in Figure 5, which contains only four limited areas, of which the area 1 is the basketball, and the rest are interference areas.  
Since in this video, the time interval between two adjacent frames is only 8.3 ms, the actual distance of the basketball in this time interval is actually very short, and the positional deviation of the basketball in the adjacent two frames is also small. We took the basketball position in the first frame image as the reference position for matching, then binarize the whole image and calculate the centroid of each region in Figure 5. After that, the distance of these centroids relative to the reference position is further calculated, and the centroid with the smallest distance is the coordinate position of the target basketball in this frame image, and the centroid calculation is shown in (6) [22].  
\[M_{pq}=\int_{a1}^{a2}\int_{b1}^{b2}x^{p}y^{q}f(x,y)dxdy \tag{6}\]  
Figure 4: RGB component acquisition process of basketball position.  
The basketball position obtained by the centroid method is more accurate, and the data in the subsequent experimental results are all the basketball positions calculated by the centroid method. By integrating the basketball positions of each frame of images, the basketball trajectory of the whole shooting process is obtained. In addition, due to the possible deviation of the calculated basketball position, individual points may deviate from the original trajectory. At this time, if it is used as a sample for training, it will cause a large error. Therefore, for the trajectory data of the training samples, this paper uses smooth interpolation to interpolate the obtained trajectory sequence to obtain a smooth trajectory sequence that is closer to the real motion trajectory.