Project Workflow:
- Takes a video of someone shooting a basketball (from a webcam or uploaded file) (typo!)
- Uses AI to detect the person's body pose (where their joints are)
- Calculates angles between body parts (elbow, wrist, shoulder, etc.)
- Scores how "good" or "bad" the shooting form is
- Provides feedback on strengths and weaknesses
- Video Input: You record or upload a video of a basketball shot
- Pose Detection: An AI model (YOLOv8) looks at each frame and finds where the person's joints are (shoulders, elbows, wrists, etc.)
- Angle Calculation: We calculate angles between joints (e.g., elbow angle, wrist angle)
- Feature Extraction: We summarize all those angles into key metrics (average elbow angle, consistency, etc.)
- Scoring: A trained machine learning model looks at those metrics and says "this is a good shot" or "this needs work"
- Feedback: The system tells you what you did well and what to improve
- FastAPI backend for uploading clips and retrieving analysis.
- YOLOv8 pose estimation + OpenCV overlay utilities.
- Pandas/NumPy data processing helpers for feature extraction.
- Scikit-learn training skeleton for classifying good vs. bad form.
- Jupyter notebook template for iterative experiments.
- Python 3.11+ (https://www.python.org/downloads/)
ffmpeg(recommended for richer video codec support)
A virtual environment is an isolated Python environment that keeps project dependencies separate from other projects. This prevents conflicts between different projects that might need different versions of the same library.
python3 -m venv .venv
source .venv/bin/activate # macOS / Linux
# On Windows (PowerShell): .venv\Scripts\Activate.ps1
# On Windows (Command Prompt): .venv\Scripts\activate.batIf the above doesn't work, try:
python -m venv .venv
source .venv/bin/activate # macOS / Linux
# On Windows (PowerShell): .venv\Scripts\Activate.ps1
# On Windows (Command Prompt): .venv\Scripts\activate.batHow to know it's working: Your terminal prompt should show (.venv) at the beginning.
To deactivate (when you're done working): Type deactivate
pip install --upgrade pip
pip install -r requirements.txtThis installs all the Python packages needed for the project. This may take a few minutes.
If the above doesn't work, try
pip3 install --upgrade pip
pip3 install -r requirements.txtA Jupyter kernel is the execution engine that runs code inside Jupyter notebooks. By registering your virtual environment as a kernel, you ensure that notebooks use the correct Python environment and packages.
python -m ipykernel install --user --name basketball-optimizer --display-name "Basketball Optimizer"If the above isn't visible in your JupyterNotebook, try:
python3 -m ipykernel install --user --name basketball-optimizer --display-name "Basketball Optimizer"If neither is available, just using the
.venv (Python 3.10.11)
is fine.
What this does: Creates a kernel named "Basketball Optimizer" that uses your project's virtual environment.
How to use it:
- In JupyterLab/Notebook: Go to Kernel → Change Kernel → Select "Basketball Optimizer"
- In VS Code: Open Command Palette (Cmd/Ctrl+Shift+P) → "Notebook: Select Notebook Kernel" → Choose "Basketball Optimizer"
uvicorn backend.app.main:app --reloadThe --reload flag automatically restarts the server when you make code changes (useful for development).
Once running, you can:
- Visit
http://localhost:8000/docsfor interactive API documentation - Visit
http://localhost:8000/healthto check if the server is running
basketball-optimizer/
├── backend/ # FastAPI backend application
│ └── app/
│ ├── api/ # API route handlers
│ ├── services/ # Business logic services
│ └── main.py # FastAPI entrypoint
├── models/ # ML model utilities and pose pipeline
├── ml/ # Machine learning training scripts
│ ├── data_pipeline.py
│ └── model_training.py
├── notebooks/ # Jupyter notebooks for analysis
│ └── pose_analysis.ipynb
├── scripts/ # CLI utility scripts
│ └── run_inference.py
├── data/ # Data storage
│ ├── raw/ # Original video files
│ ├── processed/ # Processed features and standardized videos
│ └── labels/ # Label files (CSV with good/bad shot labels)
├── docs/ # Documentation files
├── frontend/ # Frontend code (placeholder for future)
├── config.py # Configuration settings
├── requirements.txt # Python dependencies
└── README.md # This file
backend/app/main.py– FastAPI entrypoint and router wiring.backend/app/api/analyze.py– Request/response schemas and analysis endpoint.backend/app/services/pose_estimator.py– Pose estimation helpers.ml/data_pipeline.py– Dataset preprocessing and feature engineering stubs.ml/model_training.py– Model training workflow scaffold.notebooks/pose_analysis.ipynb– Analysis notebook template.scripts/run_inference.py– CLI video analysis stub.config.py– Centralized configuration (paths, settings, thresholds).
- Problem:
python3 -m venv .venvfails- Solution: Make sure Python 3.11+ is installed. Check with
python3 --version
- Solution: Make sure Python 3.11+ is installed. Check with
- Problem:
pip installfails for specific packages- Solution: Make sure you're in the virtual environment (see
(.venv)in prompt). Trypip install --upgrade pipfirst.
- Solution: Make sure you're in the virtual environment (see
- Problem: "Basketball Optimizer" kernel doesn't appear in Jupyter
- Solution: Make sure you ran the kernel registration command while the virtual environment was activated. Try running it again.
- Problem:
ImportErrorwhen running code- Solution: Make sure you're using the correct kernel in Jupyter, or that your virtual environment is activated in terminal.