Redfire-1234 commited on
Commit
f83b3ae
Β·
verified Β·
1 Parent(s): 1e30bcd

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +228 -5
README.md CHANGED
@@ -1,11 +1,234 @@
1
  ---
2
- title: Trajectory Tracker
3
- emoji: πŸ‘
4
- colorFrom: purple
5
  colorTo: purple
6
  sdk: docker
 
7
  pinned: false
8
- license: mit
9
  ---
10
 
11
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: 3D Trajectory Tracker
3
+ emoji: 🎯
4
+ colorFrom: blue
5
  colorTo: purple
6
  sdk: docker
7
+ app_file: app.py
8
  pinned: false
 
9
  ---
10
 
11
+ # 3D Trajectory Tracker
12
+
13
+ A web application that tracks objects in videos and visualizes their movement in 3D space using computer vision and Three.js.
14
+
15
+ ## Features
16
+
17
+ - πŸŽ₯ Video upload and processing
18
+ - 🎯 Automatic object detection and tracking
19
+ - πŸ“Š Real-time trajectory visualization in 3D
20
+ - 🎬 Playback controls for trajectory animation
21
+ - πŸ“ˆ Statistics and analytics dashboard
22
+
23
+ ## Technology Stack
24
+
25
+ - **Backend**: FastAPI, OpenCV, NumPy
26
+ - **Frontend**: Vanilla JavaScript, Three.js
27
+ - **Computer Vision**: Background subtraction for object detection
28
+
29
+ ## Project Structure
30
+
31
+ ```
32
+ trajectory-tracker/
33
+ β”œβ”€β”€ backend/
34
+ β”‚ β”œβ”€β”€ app.py # FastAPI main application
35
+ β”‚ β”œβ”€β”€ requirements.txt # Python dependencies
36
+ β”‚ β”œβ”€β”€ tracker.py # Object tracking logic
37
+ β”‚ └── utils.py # Helper functions
38
+ β”œβ”€β”€ frontend/
39
+ β”‚ β”œβ”€β”€ index.html # Main HTML file
40
+ β”‚ β”œβ”€β”€ app.js # Frontend logic
41
+ β”‚ β”œβ”€β”€ styles.css # Styling
42
+ β”‚ └── visualizer.js # 3D visualization with Three.js
43
+ β”œβ”€β”€ uploads/ # Temporary video uploads (auto-created)
44
+ β”œβ”€β”€ outputs/ # Processed trajectory data (auto-created)
45
+ └── README.md # Documentation
46
+ ```
47
+
48
+ ## Installation & Setup
49
+
50
+ ### Local Development (VS Code)
51
+
52
+ 1. **Clone or create the project structure**
53
+ ```bash
54
+ mkdir trajectory-tracker
55
+ cd trajectory-tracker
56
+ ```
57
+
58
+ 2. **Set up backend**
59
+ ```bash
60
+ # Create directories
61
+ mkdir backend frontend uploads outputs
62
+
63
+ # Install Python dependencies
64
+ pip install -r backend/requirements.txt
65
+ ```
66
+
67
+ 3. **Run the application**
68
+ ```bash
69
+ # From the project root directory
70
+ python backend/app.py
71
+ ```
72
+
73
+ 4. **Access the application**
74
+ - Open browser to: `http://localhost:7860`
75
+
76
+ ### Hugging Face Spaces Deployment
77
+
78
+ 1. **Create a new Space**
79
+ - Go to https://huggingface.co/spaces
80
+ - Click "Create new Space"
81
+ - Choose "Docker" as SDK
82
+
83
+ 2. **Create Dockerfile in project root**
84
+ ```dockerfile
85
+ FROM python:3.9
86
+
87
+ WORKDIR /app
88
+
89
+ # Install system dependencies
90
+ RUN apt-get update && apt-get install -y \
91
+ libgl1-mesa-glx \
92
+ libglib2.0-0 \
93
+ && rm -rf /var/lib/apt/lists/*
94
+
95
+ # Copy requirements and install
96
+ COPY backend/requirements.txt .
97
+ RUN pip install --no-cache-dir -r requirements.txt
98
+
99
+ # Copy application files
100
+ COPY backend/ ./backend/
101
+ COPY frontend/ ./frontend/
102
+
103
+ # Create directories
104
+ RUN mkdir -p uploads outputs
105
+
106
+ # Expose port
107
+ EXPOSE 7860
108
+
109
+ # Run the application
110
+ CMD ["python", "backend/app.py"]
111
+ ```
112
+
113
+ 3. **Push to Hugging Face**
114
+ ```bash
115
+ git init
116
+ git add .
117
+ git commit -m "Initial commit"
118
+ git remote add origin https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME
119
+ git push -u origin main
120
+ ```
121
+
122
+ ## Usage
123
+
124
+ 1. **Upload Video**
125
+ - Click the upload box or drag and drop a video file
126
+ - Supported formats: MP4, AVI, MOV, MKV
127
+
128
+ 2. **Process Video**
129
+ - Click "Process Video" button
130
+ - Wait for processing to complete (may take a few moments)
131
+
132
+ 3. **View Results**
133
+ - See tracking statistics (objects tracked, frames, FPS, duration)
134
+ - View 3D visualization of trajectories
135
+ - Use playback controls:
136
+ - β–Ά Play/Pause: Animate the trajectories
137
+ - ↻ Reset: Return to start
138
+ - Show Trails: Toggle trajectory lines
139
+
140
+ 4. **Interact with 3D View**
141
+ - Click and drag to rotate camera
142
+ - Scroll to zoom in/out
143
+
144
+ ## Configuration
145
+
146
+ ### Detection Methods
147
+
148
+ In `tracker.py`, you can choose detection methods:
149
+
150
+ ```python
151
+ # Background subtraction (default)
152
+ tracker = VideoTracker('video.mp4', detection_method='background')
153
+
154
+ # Color-based detection
155
+ tracker = VideoTracker('video.mp4', detection_method='color')
156
+ ```
157
+
158
+ ### Tracking Parameters
159
+
160
+ Adjust in `tracker.py`:
161
+ - `area > 500`: Minimum object size (pixels)
162
+ - `max_distance=50`: Maximum movement between frames (pixels)
163
+ - `len(points) > 5`: Minimum trajectory length (frames)
164
+
165
+ ## API Endpoints
166
+
167
+ - `GET /` - Main application interface
168
+ - `POST /api/upload` - Upload and process video
169
+ - `GET /api/trajectories/{filename}` - Get trajectory data
170
+ - `GET /api/list` - List all processed files
171
+ - `DELETE /api/clear` - Clear all data
172
+
173
+ ## Troubleshooting
174
+
175
+ ### Video Processing Fails
176
+ - Ensure video format is supported
177
+ - Check video file is not corrupted
178
+ - Verify OpenCV can read the codec
179
+
180
+ ### No Objects Detected
181
+ - Adjust detection parameters in `tracker.py`
182
+ - Try different detection methods
183
+ - Ensure objects have sufficient movement/contrast
184
+
185
+ ### 3D Visualization Issues
186
+ - Check browser console for JavaScript errors
187
+ - Ensure Three.js CDN is accessible
188
+ - Try refreshing the page
189
+
190
+ ## Development
191
+
192
+ ### Add New Features
193
+
194
+ 1. **Custom Detection Methods**: Add to `tracker.py`
195
+ 2. **UI Enhancements**: Modify `frontend/` files
196
+ 3. **Export Options**: Add endpoints in `app.py`
197
+
198
+ ### Testing
199
+
200
+ ```bash
201
+ # Test with sample video
202
+ python backend/app.py
203
+
204
+ # Access http://localhost:7860 and upload test video
205
+ ```
206
+
207
+ ## Performance Tips
208
+
209
+ - Use smaller videos for faster processing
210
+ - Reduce video resolution before upload
211
+ - Adjust detection parameters for accuracy vs. speed
212
+
213
+ ## License
214
+
215
+ MIT License
216
+
217
+ ## Contributing
218
+
219
+ Pull requests welcome! Please ensure:
220
+ - Code follows existing style
221
+ - Add tests for new features
222
+ - Update documentation
223
+
224
+ ## Support
225
+
226
+ For issues and questions:
227
+ - Open an issue on the repository
228
+ - Check existing issues for solutions
229
+
230
+ ## Credits
231
+
232
+ - FastAPI for backend framework
233
+ - Three.js for 3D visualization
234
+ - OpenCV for computer vision