Student Name: Mohammed Abdouh Ahmed Hussein(202070193) Ahmed Ahmed Abdulallah Alshibah(202070146)
Project Name: Basketball Shot Predictor Using OpenCV and Python
- Introduction
The Basketball Shot Predictor project aims to develop a predictive model that analyzes basketball shots using computer vision techniques. By leveraging OpenCV and Python, the system evaluates the trajectory of shots to determine their likelihood of success. This project combines elements of artificial intelligence, machine learning, and sports analytics.
- Objectives
- To create a system that can analyze basketball shot trajectories.
- To predict the success rate of shots based on input parameters.
- To visualize shot data and predictions in real time.
- To provide insights that can be useful for players and coaches.
- Methodology
3.1 Data Collection
Data was collected from multiple basketball games, capturing videos of shots from different angles. Key parameters were recorded, including:
- Player position
- Shot angle
- Distance from the hoop
- Speed of the shot
3.2 Image Processing
Using OpenCV, we processed the captured video frames to detect the basketball and hoop. Key steps included:
- Frame Extraction: Extract frames from the video at specified intervals.
- Color Detection: Identify the basketball using color filtering techniques.
- Contour Detection: Use contour detection to locate the hoop within the frame.
3.3 Feature Extraction
From the processed images, we extracted relevant features, such as:
- Shot angle (calculated based on player position and hoop position)
- Velocity of the ball (computed using frame differences)
- Distance from the hoop (geometric calculations based on coordinates)
3.4 Machine Learning Model
A machine learning model was trained using the extracted features and historical shot data. The model aimed to predict the success of a shot based on the input parameters. Techniques used included:
- Data Preprocessing: Normalization and splitting the data into training and testing sets. The model's performance was evaluated using metrics such as accuracy, precision, and recall.
- Implementation
4.1 Tools and Technologies
- Programming Language: Python
- Libraries: OpenCV, NumPy, scikit-learn, Matplotlib
- Development Environment: Jupyter Notebook
4.2 System Architecture
The system consists of the following components:
-
Video Input: Captured video of basketball games.
-
Image Processing Module: Processes each frame to identify the ball and hoop.
-
Feature Extraction Module: Extracts relevant features for prediction.
-
Prediction Module: Uses the trained model to predict shot success.
-
Visualization Module: Displays the results and predictions in a user-friendly manner.
-
Results The model achieved an accuracy of approximately 85% on the test dataset. Key findings include:
- Shots taken from closer distances had a significantly higher success rate.
- The angle of the shot played a crucial role in determining success.
Visualizations showed the predicted probabilities of success for various shots, allowing for a comprehensive analysis.
- Conclusion
The Basketball Shot Predictor successfully demonstrated the feasibility of using computer vision and machine learning to analyze and predict basketball shots. The insights gained from this project can aid players in improving their shooting techniques and help coaches make data-driven decisions.
- Future Work
Future enhancements may include:
- Incorporating more advanced machine learning techniques such as deep learning.
- Expanding the dataset to include various player skill levels.
- Developing a mobile application for real-time shot analysis.
- References
- OpenCV Documentation: OpenCV
- Machine Learning Resources: scikit-learn
- Sports Analytics Literature: Relevant academic journals and publications on sports technology.