I have started to build a tablesoccer Video analysis with openCV, Python and a Basler camera. For now, I have realized the basic structure for the analysis, ball tracking, field detection, goal counting and ball speed calculation.
Hardware license: Solderpad 0.51
Table Soccer Video Analysis with OpenCV in Python - Basler dart / pulse Camera connected with PyPylon
During my own websearch couple of weeks ago I found some impressive demonstrations of video analysis setups for table soccer matches. But sadly none of those mostly university groups have published their code.
So not that long ago I began coding an OpenCV based ball-detection as a first step realizing the project. It became clear pretty fast that I won't be able to do all of the coding by myself, so I decided to release the project to all of you already although there still is a lot of work to be done before the project could somehow be called as "finished".
This is my setup.
I’m using a Basler pulse camera positioned about 1.5 meters on top of the soccer field for filming the field area of the table. I had to crop the sensors image to increase the framerate. The downside of that is that I now need a vocal length of about 4mm.
On the script side I decided to use Python for some straight forward results combined with the OpenCV library for image recognition.
To get the raw camera image I’m using a Python wrapper for Baslers C++ API, which allows me to configure all advanced camera settings within the code.
I focused a lot on writing the project code in a as modular way as possible so it will be easy to adapt new awesome features you might want to add to it.
So here's what I've done for now
- Basic structure with clear separation between
- camera interaction
- several analyzing classes
- a universal output class
- Ball tracking with automatic color calibration
- Field detection (orientation, scale, goal line, etc.)
- Goal detection and counting
- ball speed calculation in m/s
- Heatmap generation when a match is finished
Currently there are two main classes. One is detecting the field with its orientation, size and goal area position. It also creates a pixel per inch ratio for things like speed calculation. The second is responsible for the calibration and detection of the ball. It can detect most ball colors. The color just has to be different than the field colors.
Obviously there is plenty of work to do and probably you have even more great ideas what can be done for a great user experience. Here I some ideas which I would like to implement if I have enough time in the future.
- ball prediction for a faster ball detection
- Web-based user interface with a responsive design to be usable on any device with Bluetooth or wifi
TableSoccerCV is hopefully just the beginning of some great Open Source table soccer video analysis projects. I hope you find my code useful! Cheers, StudentCV
0.1 - PreRelease
You will need the following packages for python to get the code working:
- Python 3.4
- OpenCV 3.0
- PyPylon 1.0.5 Get it here
Want to contribute? Great!
The code itself is documented within the source code as much as possible. I'll also provide a short coding manual asap.
Feel free to add some great functionalities!