When we started exploring sports analytics, we wanted to answer a deceptively simple question: can a computer determine whether a basketball shot goes in or hits the rim just by watching video footage? Traditional object tracking could locate the ball, but understanding the physics of the shot required something more. So we built a computer vision system that tracks basketball trajectories, predicts projectile motion using polynomial regression, and detects rim collisions through statistical analysis.
This is the story of how we combined computer vision, projectile physics, and regression analysis to build a basketball shot analyzer capable of distinguishing made shots from rim collisions.
Humans can instantly tell whether a basketball shot is on target. We intuitively understand the arc of the ball, how it should travel through the air, and whether it interacts with the rim.
Computers do not have that intuition.
Most object tracking systems stop at identifying where an object is located. They do not reason about motion patterns, physical trajectories, or unexpected disruptions in movement.
We needed a system that could:
The challenge was transforming raw pixel coordinates into meaningful physical insights.
Everything begins with accurately locating the basketball.
Video footage contains multiple moving objects, varying lighting conditions, camera motion, and background distractions. The first task was isolating the basketball from everything else in the scene.
Using OpenCV, we processed each frame and applied color filtering and contour detection techniques to identify the ball.
The tracking pipeline looked like this:
Video Frame
↓
Color Filtering
↓
Contour Detection
↓
Ball Identification
↓
Coordinate Extraction
↓
Trajectory History
For every frame, the system records the ball's center coordinates, gradually building a sequence of points representing the shot's motion through space.
This coordinate history becomes the foundation for trajectory prediction.
A basketball shot behaves approximately like a projectile.
Ignoring air resistance and spin, the path of the ball follows a parabolic curve. This means we can model the trajectory using a second-degree polynomial.
The mathematical form is:
y = ax² + bx + c
Instead of manually estimating the curve, we use polynomial regression to fit the trajectory based on observed ball positions.
As more frames are processed, the model continuously updates its estimate of the shot path.
This allows the system to predict:
The result is a mathematical representation of the shot rather than simply a collection of tracked points.
Once enough tracking points have been collected, the system fits a second-degree polynomial to the observed coordinates.
The workflow is straightforward:
Tracked Coordinates
↓
Polynomial Regression
↓
Best-Fit Parabolic Curve
↓
Trajectory Prediction
A properly executed basketball shot produces a smooth and predictable curve.
As long as the ball remains in free flight, the regression fit remains extremely stable.
This observation became the key to solving the collision detection problem.
Detecting a rim collision is surprisingly difficult.
Traditional methods often rely on precise rim detection, object overlap calculations, or complex physics simulations. These approaches become unreliable when video quality drops or camera angles change.
Instead, we focused on the trajectory itself.
When a basketball follows a natural projectile path, its motion closely matches a parabolic curve.
When the ball strikes the rim, however, its path changes abruptly.
This sudden deviation introduces error into the polynomial fit.
To quantify that error, we used the coefficient of determination, commonly known as R².
R² measures how well the observed data matches the fitted trajectory.
A value close to 1 indicates that the ball is following a predictable projectile path.
A lower value indicates that the motion no longer matches the expected parabola.
Our collision detection logic became:
R² ≥ 0.99
→
Smooth Projectile Motion
R² < 0.99
→
Potential Rim Collision
During testing, successful shots maintained extremely high R² values throughout the trajectory.
Shots that clipped the rim or bounced away showed sudden drops in R² at the moment of impact.
This provided a surprisingly robust collision indicator without requiring explicit rim-contact detection.
Detecting a collision is only part of the problem.
The system also needs to determine whether the shot was successful.
To accomplish this, we analyze the relationship between the predicted trajectory and the hoop region.
The classification process is:
1. Track the ball trajectory
2. Fit the polynomial curve
3. Evaluate R² stability
4. Check trajectory intersection with hoop area
5. Determine post-intersection motion
If the trajectory smoothly enters and exits through the hoop region without significant disruption, the shot is classified as successful.
If the trajectory intersects the rim area and experiences a sudden deviation, it is classified as a rim collision.
This combination of geometric analysis and statistical monitoring proved more reliable than relying on either technique independently.
One of the most valuable components of the project was trajectory visualization.
For every shot, the system can display:
The visualization pipeline made it significantly easier to understand model behavior and identify tracking errors.
It also provided coaches and analysts with an intuitive way to inspect individual shot outcomes.
Several design decisions contributed significantly to the project's success.
Basketball trajectories naturally align with parabolic motion, making second-degree regression both simple and effective.
Monitoring regression quality turned out to be a lightweight yet powerful way to detect trajectory disruptions.
The combination of OpenCV tracking and lightweight mathematical models enabled near real-time analysis.
Trajectory overlays and curve visualization dramatically improved development and validation.
The current approach relies primarily on traditional computer vision techniques. Modern object detectors such as YOLO could improve robustness under difficult conditions.
The system currently assumes knowledge of the hoop region. Future versions could automatically detect the basket using computer vision.
Using multiple camera angles would improve trajectory reconstruction and reduce occlusion issues.
Beyond make-or-miss classification, future versions could estimate launch angle, release velocity, arc quality, and expected shot success probability.
A computer vision-powered basketball analytics system capable of tracking shots, modeling projectile motion, predicting trajectories, and detecting rim collisions using statistical analysis.
By combining OpenCV tracking, polynomial regression, and R²-based collision detection, the platform transforms ordinary basketball footage into actionable shot analytics without requiring specialized hardware or sensors.
The project demonstrates how mathematical modeling and computer vision can work together to extract meaningful insights from sports footage, turning every shot into a measurable and analyzable event.
Looking to build custom sports analytics solutions? We develop computer vision systems for player tracking, performance analysis, event detection, and AI-powered sports intelligence platforms.