To overcome the challenge of detecting small baseballs against complex backgrounds (pitcher’s mound, crowd, grass), run.py implements the following pre-processing techniques:
- Dynamic Image Sharpening: Calculates difference maps via Gaussian Blur and addWeighted to sharpen localized high-frequency edge features of fast-moving baseballs.
- MOG2 Background Subtraction & Sky ROI Mask (Optional): Utilizes BackgroundSubtractorMOG2 to extract dynamic foregrounds and sky masks for background noise suppression.
- Dynamic Local ROI Cropping: When a ball is detected in the previous frame, the subsequent frame dynamically crops a 500×500 pixel window centered at the ball’s coordinates for YOLO inference. If the trajectory is lost for over 30 consecutive frames, it resets to default initial bounds, dramatically accelerating inference speed and eliminating background false positives.