Just a note this hasn't been tested.
Once you extract ball's location, you can get its contours. My suggestions will work only with soccer balls that have lighter patches and darker patches (which are pentagons).
Determine good binary threshold to grab both white and black patches. Do some image manipulation like erode or dilate to get rid of cracks between patches made by stitches. Draw white circle around the ball to make sure none of your black patches are considered a "hole in the ball" and you're ready to grab contours inside the ball. Main contour is the white countour made by white patches, and all black contours are the dark patches.
Weak points: Dirty ball can have issues with binary thresholding, maybe use adaptive threshold?
1. Using look-up table/math formula(?) for black patches size and distance
Black patch's size depends on the distance from center of the ball. Feed the algorithm with learning data on black patches distances from center and their sizes (both values relative to the ball size).
For example:
Ball in recorded frame has bounding box of 200x200 px and area of 30000px
Found 6 black patches inside:
patch 1 is in the middle (distance 0px from center) and has area of 600px
patch 2 is on the side (distance 50px from center) and has area of 150px
patch 3... patch 4... and so on
So you feed your lookup table with data:
distance = 0% -> area = 2%
distance = 25% -> area = 0.5%
distance = ... -> area = ...
and so on
Now when you check if the thing you detected is a ball, check their black patches sizes. If most of their sizes and distances from center of the ball are within accepted ranges, the detected object is a ball.
2. Checking contour shape
You can check each contour using cvApproxPoly
. If most black contours are pentagons - it's a ball.