Volleyball tracking on drone video with OpenCV and Canny edge detection
Last year I worked on ball recognition and tracking using volleyball videos from Youtube and even launched a service for people who want to do something with their games records.
Recently I got a drone and the first thing I did of course — filmed our game with friends in a park. Hovering at the altitude of 40–50 feet is enough to catch the whole court and the captured video gives many analytic opportunities.
But first thing first and let's check how the ball tracking works here. The drone carries the camera with a gimbal which absorbs the drone movements.
The video from the camera looks perfectly stable, but my approach, based on background removal failed here:
An explanation is gimbal stabilization is not perfect and the frames have small fluctuations invisible by the human eye. But computers have sharper vision and they see the difference. So the background is pretty vivid:
Just for comparison — a similar static video with the removed background looks like this:
So we have nothing to do but find new ways. Fortunately, OpenCV is an old and rich library and has many algorithms to check out.
In the past, I had experience with Canny edge to find objects by their contours.
gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
gray = cv.GaussianBlur(gray, (5, 5),0)
mask = cv.Canny(gray, 50, 100)
Applying this algo to drone video gives promising results:
As one can see the ball is recognized and tracked. It is interesting, Canny provides worse (than background removal) results on really static videos, so we cannot use it everywhere. It could be explained that Canny recognizes many background objects and the ball could be lost when flying over.
Then remove the background on Canny-filtered image:
mask = backSub.apply(frame)
mask = cv.dilate(mask, None)
mask = cv.GaussianBlur(mask, (15, 15),0)
ret,mask = cv.threshold(mask,0,255,cv.THRESH_BINARY | cv.THRESH_OTSU)
A serve track is pretty accurate now:
More my articles about volleyball and computer vision
Ball tracking in volleyball with OpenCV and Tensorflow
Computer vision and neural networks in SportTech
Cut Highlights From Volleyball Game With Ball Tracking and Computer Vision
Recently I started with ball tracking in volleyball and the experiment promised interesting results — an ability to cut…