8 min read
Tennisball Tracking
I’m excited to share my latest project where I measured the speed of a tennis ball using basic video processing techniques. Below, you’ll find a detailed explanation of what I did, how I did it, and the technology behind the project.
What I Did
-
Captured Video Footage:
- Recorded via a Drone (DJVI-Pro) a tennis court from a top-down perspective to ensure a complete and unobstructed view of the ball’s flight.
- The input video needs a resoloution at 1280x720, for a clear view of the Ball movement.
-
Developed a Custom Software Program:
- Designed and implemented a program capable of processing video footage frame by frame.
- Integrated image processing techniques to detect and track the tennis ball throughout its trajectory.
-
Visualized the Trajectory:
- The program not only calculates speed but also visualizes the flight path of the tennis ball, making it easier to understand the ball’s motion dynamics.
How It Works
1. Video Processing and Ball Tracking
-
Frame Extraction:
- The video is split into individual frames.
- Each frame is analyzed to detect the position of the tennis ball.
-
Court Detection:
- Court corners are identified using a robust line detection method. This involves applying a threshold to highlight potential lines, followed by morphological operations to enhance both horizontal and vertical lines. Finally, the intersections of these lines are determined, accurately marking the court corners.
- Stabilize the wacky drone video by ankering it to the marked corners.
- The absolute difference between two consecutive frames is computed to isolate moving objects.
-
Ball Detection:
- Picking out light objects.
- Utilized computer vision algorithms to distinguish the tennis ball from the background.
- Applied filtering and thresholding techniques to enhance the detection accuracy.
- Add a logical algorithm that identifys the ball by its possible movements.
-
Trajectory Mapping:
- The detected positions of the ball in consecutive frames are connected to form its trajectory.
- This trajectory is visualized as an overlay on the original video footage.
Trajectory Visualization
Below is an example of the trajectory mapping overlaid on the court:

2. Speed Measurement
-
Maximum Speed (Maxspeed):
- Measured immediately after the ball is hit.
- Focused on capturing the peak speed, which is then compared to benchmarks from professional tennis players.
- Provides an indicator of the shot’s power and performance.
-
Average Speed:
- Calculated over the entire duration of the ball’s flight.
- Offers insights into the consistency and overall dynamics of the shot.
- Helps in understanding how the ball decelerates due to factors like air resistance and spin.
3. Data Analysis and Visualization
-
Speed Calculation:
- Computed by analyzing the change in the ball’s position between consecutive frames.
- Factored in the frame rate and spatial resolution to ensure precise speed estimation.
-
Graphical Representation:
- Generated plots and overlays to visually represent both the trajectory and speed data.
- Provided clear and interactive visual feedback, making it easier to interpret the results.
4. Adding CUDA for More Performance
I compiled OpenCV with CUDA support so I could leverage the GPU (in this case, an RTX 4060) for image processing algorithms. As a result, the frame rate increased from 34 FPS to 173 FPS, enabling real-time performance. This boost allows the system to monitor multiple courts simultaneously without sacrificing accuracy.
Performance Comparison:

Why This Project Matters
-
Integration of Sports and Technology:
- Combines sports analytics with computer vision, showcasing how technology can enhance our understanding of athletic performance.
-
Benchmarking with Professional Standards:
- By comparing the maximum speed against professional player data, the project provides meaningful insights into the performance quality of tennis shots.
-
Educational Value:
- This project served as an excellent learning opportunity, integrating concepts from video processing, data analysis, and sports science.
Conclusion
Through this project, I was able to merge the fields of sports analytics and technology to create a tool that not only measures but also visualizes the speed of a tennis ball in a highly detailed manner. The insights gained from this work could be valuable for both players and coaches aiming to improve performance.
Feel free to ask any questions or share your feedback!
Cheers!