Professional Documents
Culture Documents
Introduction
Its March madness month! And what an exciting season it has
been. For the data scientist within you lets use this opportunity
to do some analysis on basketball clips. With the use of deep
learning and opencv we can extract interesting insights from
video clips. See example gif below of the game b/w UCF and
Duke where we can identify all the players + referees, label
players into teams based on their jersey colour. Later in the blog
I show how we can also identify which player is attempting to
shoot the basket . And all of this can be done real time.
Detecting players and teams
So let’s start.
Detecting Players
I have used a pretrained detection model like the Faster
RCNN to detect players. It is easy to download a Faster RCNN
trained on the COCO data set from the Tensorflow Object
Detection API and test it. The API takes as input each frame of
image and detects among 80 different classes. If you are new to
Tensorflow Object Detection and want to learn more, please
checkout this blog. The model does quite well in detecting
persons but there are many detections in this video due to the
large number of people in the crowds. See sample detection
below. I suppressed detections that were too big to more cleanly
segment out players. You can also play with the score threshold
in the API to filter out low confidence detections. Checkout the
code on Github for tips on how to suppress boxes with low
scores and multiple false detections.
Detecting Teams
Now comes the interesting part. How do we detect which
players are UCF vs Duke? We can use OpenCV to do that.
OpenCV Tutorial
See output below for white colour. They are masked as “pink”
with everything else in the background in black
We can look for players with their wrist keypoints above their
head. Implying hands raised. This could indicate ready to shoot
as in the scene above or could be defensive. Further the
coordinates of the ball along with those of the wrist keypoint can
be used to identify which player with raised hands has ball close
to them.
Conclusion
Deep learning has made is possible to do really cool analysis by
chaining different ideas. There is a lot of open source code and
pretrained models that you can use on your data to get started.
Above is just the starting point. Other cool things that can be
done include:
References