The algorithm is designed to detect the elements of table tennis gameplay. The test dataset contains videos recorded from a static position. The camera is always behind the back of one of the players.
Table tennis entities detection is based only on the classic computer vision and clustering algorithms.
Installation
Due to the use of only image operations and unsupervised clustering algorithms, the GPU is not required. To prepare the environment, just install the libraries from requirements.txt.Running
Temporarily there is no specific script configuration. An example usage is in the main.py file.The result of the algorithm are points representing the coordinates of corners of the table, and the players bounding boxes.
Table corners detection
Table contours detection
Table lines detection is based on the Probabilistic Hough Transform. Successive frames are transformed and detected lines are saved in the mask. When iteration is done, the mask contains the table lines and excess lines detected outside the table.
On the finished mask, connected components are detected, and the component closest to the center of the image is selected.
Table mask corners detections
Mask lines detection is based on Hough Line Transform.
The algorithm filters redundant lines which rho and theta values are close to each other.
The lines are clustered due to the angle of inclination. Clustering is done by the DBSCAN algorithm. Outlier lines are removed from lines list.
All points of intersection between the horizontal and vertical lines are calculated basis on theta and rho of lines.
The Intersections are clustered due to the position on the Cartesian plane. Clustering is done by the DBSCAN algorithm.
Intersection cluster centroids are calculated as the average of all existing points in the cluster.
Players detection
Due to the fact that table tennis is very dynamic, it is possible to create a mask of the differences between the frames to target the most dynamic elements of the image
Thanks to the preserved perspective, it is possible to separate the parts of the image where the lower player and the upper player can be located, the detection takes place separately on both parts of the image.
Separate difference mask elements are detected using the connected components algorithm. The largest masks on separate regions of interest are considered player masks.