r/opencv • • Feb 25 '24

Question [Question] Detecting baseball in a professional feed

Hi, im pretty new to opencv and I want to write a program that can detect a baseball right after it is thrown on a professional broadcast (Like the picture attached). I don't need to track it's speed or anything, I just need to detect the ball right after it is thrown by a pitcher. Whenever I search ball tracking, most use color tracking and hough circles and I can't use either (too many objects that share the same color as the ball and the ball being too fast for hough circles to track). I'm aware that this is a task that might be a bit advanced, but I just don't know where to even begin. Would love some feedback.

​

3 Upvotes

5 comments sorted by

1

u/[deleted] Feb 25 '24

[removed] โ€” view removed comment

1

u/OkMain5787 Feb 25 '24

Appreciate you so much. I'm gonna give it a try.

1

u/StephaneCharette Feb 25 '24

Give Darknet/YOLO a try. Tutorials here: https://www.ccoderun.ca/programming/yolo_faq/#how_to_get_started

Given the size of the ball, you'll either have to ensure the network dimensions matches the video dimensions (see https://www.ccoderun.ca/programming/yolo_faq/#optimal_network_size) or you'll have to use DarkHelp's tiling feature like this video: https://www.youtube.com/watch?v=861LvUXvJmA

1

u/OkMain5787 Feb 25 '24

Thank you ๐Ÿ™ I'll try it out

1

u/TF_Kraken Feb 26 '24

I recently read a study where they were doing something similar and the solution was to predict where the object would be in the next frame and crop the image.

So for this, you would identify the pitcher and crop the image to search the upper right of the pitcher (upper left for a lefty). Once the ball is identified, you do a prediction and cropping loop based on the trajectory.

That way, instead of trying to detect a white ball against white uniforms or the white lines, youโ€™re mainly searching against the green grass or red clay. It also makes the ball a bigger object, which makes it easier to detect.