File size: 3,299 Bytes
d1dd306
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Development Commands

### Running the Application
```bash
# Install dependencies
pip install -r requirements.txt

# Start the FastAPI server
uvicorn app:app --host 0.0.0.0 --port 7860

# Alternative development server with reload
uvicorn app:app --reload
```

### Docker Deployment
```bash
# Build the Docker image
docker build -t sportsai .

# Run the container
docker run -p 7860:7860 sportsai
```

### Environment Setup
- Create `.env` file with required environment variables:
  - `API_URL`: External API endpoint URL
  - `API_KEY`: Authentication key for external API
  - `AI_API_TOKEN`: Token for authenticating incoming requests

## Architecture Overview

### Core Components

**FastAPI Application (`app.py`)**
- Main web server with two primary endpoints:
  - `/upload`: General video processing with pose estimation
  - `/exercise/salto_alto`: Specialized high jump exercise analysis
- Uses background tasks for asynchronous video processing
- Handles file uploads and API authentication

**Pose Estimation (`vitpose.py`)**
- Wraps the `rt-pose` library with VitPose model
- Provides pose estimation pipeline with CUDA/CPU support
- Handles video-to-frames conversion and frame annotation
- Automatically rotates landscape videos to portrait orientation

**Video Analysis (`tasks.py`)**
- Contains `process_salto_alto()` function for high jump analysis
- Implements comprehensive jump metrics calculation:
  - Jump height detection using pose keypoints
  - Sayer power estimation
  - Repetition counting
  - Metrics visualization overlay
- Sends results to external API endpoints via webhooks

**Configuration (`config.py`)**
- Manages environment variables and API credentials
- Uses python-dotenv for environment file loading

### Key Features

**High Jump Analysis Pipeline:**
1. Video upload and pose estimation using VitPose
2. Calibration using person height in first frame
3. Jump detection based on ankle movement thresholds
4. Real-time metrics calculation and overlay visualization
5. Results packaging and webhook delivery

**Pose Estimation:**
- Uses PekingU/rtdetr object detection + usyd-community/vitpose-plus-small
- Supports both CUDA and CPU inference
- Model compilation enabled for performance optimization

**Video Processing:**
- Automatic landscape-to-portrait rotation
- Skeleton visualization with keypoint connections
- Metrics overlay with rounded rectangles and real-time updates

### Dependencies
- **FastAPI**: Web framework for API endpoints
- **rt-pose**: Pose estimation pipeline
- **OpenCV**: Video processing and computer vision
- **Supervision**: Keypoint visualization utilities
- **PyTorch**: Deep learning framework for pose models

### File Structure
- `app.py`: Main FastAPI application
- `vitpose.py`: VitPose wrapper class
- `tasks.py`: Video processing and analysis functions
- `config.py`: Environment configuration
- `requirements.txt`: Python dependencies
- `Dockerfile`: Container deployment configuration
- `static/`: Directory for processed video outputs (git-ignored)

### API Authentication
All endpoints require token-based authentication via header or body parameters. Unauthorized requests return 401 status codes.