I can now draw trajectories of pool balls in a video clip!

Pubo

Active member
I posted a question before about how I can track cue ball (or any ball) using some codes https://forums.azbilliards.com/threads/how-to-track-cue-ball-movement.552461/#post-7506743. Now I found a method in OpenCV that works pretty well for slow-mo videoes. Here are some demo clips I made


The algorithm is Optical Flow introduced here https://docs.opencv.org/3.4/d4/dee/tutorial_optical_flow.html, and since when I'm filming slomo videos I need strong light. The light will create a bright spot on the ball that doesn't change location on the surface of the ball if the movement of ball is relatively stable with respect to the camera. The algo will track the bright spot on the surface and draws out the trajectory of the balls. Solid balls work best with this approach.
 
This is really cool. I hope Dr. Dave, Sharivari, and the other instructors that are into video graphics show an interest. Really impressive.
Thanks! I'll improve them before they are even useful for the public haha. Now it's just at working stage, but far from useful:)
 
Nice! For other ball metrics like speed and spin, look at using OpenCV's SIRF to target key features on the ball for spin/speed calculations. Here's a tutorial on how use key features for golf ball spin:

https://www.golf-simulators.com/GolfSimulatorTheory.html

Because cue ball speed is slow, you might be able cheat without using high FPS. I've been able to use cv2.HoughCircles to identify circles in full speed video. If you want to do ball identification, you should be able to find a pre-trained model online.


 
Nice! For other ball metrics like speed and spin, look at using OpenCV's SIRF to target key features on the ball for spin/speed calculations. Here's a tutorial on how use key features for golf ball spin:

https://www.golf-simulators.com/GolfSimulatorTheory.html

Because cue ball speed is slow, you might be able cheat without using high FPS. I've been able to use cv2.HoughCircles to identify circles in full speed video. If you want to do ball identification, you should be able to find a pre-trained model online.


Thanks for the tips! I'll check out the resources:) I think HoughCircles sometimes detect circles out of nowhere, right?
 
Thanks for the tips! I'll check out the resources:) I think HoughCircles sometimes detect circles out of nowhere, right?

Yeah, you'll need to tinker with the parameters and sort and filter the circles by size to eliminate false positives. For something as large as a pool ball it does a good job.
 
Nice! For other ball metrics like speed and spin, look at using OpenCV's SIRF to target key features on the ball for spin/speed calculations. Here's a tutorial on how use key features for golf ball spin:

https://www.golf-simulators.com/GolfSimulatorTheory.html

Because cue ball speed is slow, you might be able cheat without using high FPS. I've been able to use cv2.HoughCircles to identify circles in full speed video. If you want to do ball identification, you should be able to find a pre-trained model online.


I tried the HoughCircle it works great! I just need to find the radius of the ball in each given video and that's pretty much it! THank you!
 
I tried the HoughCircle it works great! I just need to find the radius of the ball in each given video and that's pretty much it! THank you!

These parameters work for me for most use cases.

circle_params = dict(
dp=1, # Inverse ratio of the accumulator resolution to the image resolution
minDist=50, # Minimum distance between the centers of the detected circles
param1=50, # Upper threshold for edge detection
param2=30, # Threshold for center detection
minRadius=100, # Minimum radius of the detected circles
maxRadius=600 # Maximum radius of the detected circles
)

circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, **circle_params)

HoughCircles will return the radius of each detected circle, which you can use to determine pixels per inch in your image because ball radius will be near 2.25in. Once you know that metric, you can calculate ball speed.
 
These parameters work for me for most use cases.

circle_params = dict(
dp=1, # Inverse ratio of the accumulator resolution to the image resolution
minDist=50, # Minimum distance between the centers of the detected circles
param1=50, # Upper threshold for edge detection
param2=30, # Threshold for center detection
minRadius=100, # Minimum radius of the detected circles
maxRadius=600 # Maximum radius of the detected circles
)

circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, **circle_params)

HoughCircles will return the radius of each detected circle, which you can use to determine pixels per inch in your image because ball radius will be near 2.25in. Once you know that metric, you can calculate ball speed.
This will work with the top view of the table right? If you get background then a lot of stuff can be detected as circles
 
I
These parameters work for me for most use cases.

circle_params = dict(
dp=1, # Inverse ratio of the accumulator resolution to the image resolution
minDist=50, # Minimum distance between the centers of the detected circles
param1=50, # Upper threshold for edge detection
param2=30, # Threshold for center detection
minRadius=100, # Minimum radius of the detected circles
maxRadius=600 # Maximum radius of the detected circles
)

circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, **circle_params)

HoughCircles will return the radius of each detected circle, which you can use to determine pixels per inch in your image because ball radius will be near 2.25in. Once you know that metric, you can calculate ball spee
Let me know if you figure it out. I failed but I don’t have an image processing background
Sure! I didn't write anything original. All essential tools come from OpenCV. Just try out different things haha
 
Back
Top