Tennis Ball Line Calling System



Project Description:
• Create a system using Python and OpenCV that will track tennis balls as they fall and determine if they are in or out
• Use OpenCV along with a variety of filters to identify and track the ball as it lands
• Utilize two cameras coming from different angles to ensure that the ball being tracked is the correct object and not erroneous data from a single camera
• Reduce costs by reusing Motorola G4 Play Cameras from my high school robotics team, FTC 12823 Crescendo.

Initial prototype in early February 2023:




Project Technical Specifications
• The project uses a variety of filters to properly identify the ball. This starts with a color filter as well as a gaussian blur to eliminate some noise.
• Additionally, 3 erodes are used to make boundaries less defined before applying 2 dilates to combine the blobs into a more solid chunk.
• After this, the max countours are pulled from this and the object is considered a ball if the radius is greater than 3. This ensures we are actually detecting something meaningful.
• Finally, manual calibration is performed to find the coordinates where the ball would be considered out. These are tracked in both of the cameras and result in the buzzer going off whenever the ball goes outside of the acceptable boundaries.
• An example of the filters applied to an image from both cameras can be seen below.




Design Choices:
• 2 Cameras are utilized with the possibility to expand to more cameras to cover more areas of the court.
• Since the court had issues with wifi in addition to the existing camera lag issues, I opted to use a USB connection with Iriun. Other options explored include DroidCam and IPWebcam. These proved to be less effective than Iriun.
• Even with a camera tilt, one of the cameras could still see objects outside of the court. To solve this, a section of code is implemented to black out pixels above a certain value (seen below).



Challenges:
• Lighting: Sunlight made testing the system incredibly difficult. An indoor court would have been a better way to help reduce interference from the sun. Intereference was reduced by tilting the cameras towards the floor away from the sun. This also helped with avoiding detecting random objects that aren't the ball.
• Camera Quality: The Motorola G4 Play cameras restricted the ability of the system by requiring the cameras to be much closer to line than expected. A higher resolution camera would allow us to have the camera off the court (similar to the actual Hawkeye system).
• Camera Mounting: The cameras needed to be further off the floor to properly see the ball. Rather than redesigning the mounts in Solidworks (not the focus of this project), I opted to use a stack of books to reach the appropriate height needed.
• Camera Lag: Detection lag caused by having two cameras and blacking out certain pixels caused some problems, but these were somewhat mitigated with the USB connection rather than a WIFI connection.

Video Demo of System:

If you're interested, check out the source code here as well as this link to the STL file for the phone holder.


Copyright© 2024 Lucas Luwa. All Rights Reserved.