In the game of Snooker, if your opponent misses the object ball entirely, it's a foul shot and you can have the balls put back to their original positions and have them play again and again until they hit the ball-on, or when there's not enough points on the table for them to win due to the foul points given away.
The only problem is, many balls can be disturbed in a foul shot and all of them have to be replaced with extreme precision, otherwise the match outcome is affected. Both players have to agree on the replacements and there can be disputes and arguments, slowing the match down for up to several minutes at a time.
No doubt many important matches worth $100,000+ have had their match outcomes affected as a result of inaccurate ball replacements, arguments between players, and disruption of flow and focus. Not to mention the crowd get bored out of their mind waiting.
But there's a better way! With the help of software and lasers, you don't have to rely on memory and we can speed up the process and make it more accurate.
I am using a Windows Forms C# .Net App, with the Emgu.CV package for edge detection in images and the Aforge.Video package to handle incoming camera frames. To get live video input I use my phone's camera running Iriun Webcam, a free app that streams video over wifi. The pc also runs iriun as a receiver.
The main form allows you to take in either pre-recorded videos for testing or live camera. It attempts to detect the cueball in every frame and track shots, which is what happens from when the cueball starts moving to when it stops moving.
When you want to replace the balls in the event of a miss or foul, you simply select the frame before the miss and open up the Ball Replacer form.
This form shows the starting table position with the live camera feed superimposed on it at a lower opacity. Here you can quickly and accurately replace the balls by moving them until they both match up and appear as one. This is a manual method but it is very accurate and relatively fast, and certainly superior to relying solely on memory.
To identify the cueball in the image, it uses an RGB mask for both the cloth and cueball colour, which is fine tunable with a Debug Video form. You can also enable blurring/sharpening, and table-edge filtering. In this form, it also shows all the stages of image processing to identify where the processing or masking is going wrong. The changes are effective immediately and work while video or camera is being processed.
I use a Tripod positioned high up on a box to hold the phone to get a view of the whole-table.
For the laser turret, I use a pan/tilt mount originally meant for action cameras and put two 420:1 gear reduction stepper motors inside and mounted a red laser module on the top. Each stepper motor is driven by driver module mounted to a CNC shield connected to an Arduino Uno. The driver modules are A4988 chips. This is then plugged into my laptop.
The motors use about 9000 steps to revolve once, so this enables sufficiently precise movements on the table even from one metre+ away.
Checkout the GitHub project for development updates.
Last modified: 22 January 2025