setup husky prettier eslint
This commit is contained in:
94
Readme.md
94
Readme.md
@@ -63,11 +63,13 @@ YOLOPOTHOLE/
|
||||
## 📦 Prerequisites
|
||||
|
||||
### Backend
|
||||
|
||||
- Python 3.9+
|
||||
- CUDA-compatible GPU (optional, recommended)
|
||||
- FFmpeg
|
||||
|
||||
### Frontend
|
||||
|
||||
- Node.js 18+
|
||||
- npm/yarn/pnpm
|
||||
|
||||
@@ -116,6 +118,7 @@ npm install @radix-ui/react-scroll-area
|
||||
### Backend Configuration
|
||||
|
||||
**`app/core/storage.py`**
|
||||
|
||||
```python
|
||||
from pathlib import Path
|
||||
|
||||
@@ -135,6 +138,7 @@ MODELS_DIR.mkdir(exist_ok=True)
|
||||
```
|
||||
|
||||
**`main.py`**
|
||||
|
||||
```python
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
@@ -166,6 +170,7 @@ if __name__ == "__main__":
|
||||
### Frontend Configuration
|
||||
|
||||
**`.env.local`**
|
||||
|
||||
```bash
|
||||
NEXT_PUBLIC_WS_URL=ws://localhost:8000/api/v1
|
||||
```
|
||||
@@ -173,6 +178,7 @@ NEXT_PUBLIC_WS_URL=ws://localhost:8000/api/v1
|
||||
### Model Configuration
|
||||
|
||||
**Adaptive Parameters** (in `video_processor.py`):
|
||||
|
||||
```python
|
||||
# Speed < 30 km/h: ROI 50%, Confidence 0.35
|
||||
# Speed 30-60 km/h: ROI 65%, Confidence 0.28
|
||||
@@ -223,6 +229,7 @@ npm start
|
||||
### REST Endpoints
|
||||
|
||||
#### 1. Upload Video
|
||||
|
||||
```http
|
||||
POST /api/v1/upload
|
||||
Content-Type: multipart/form-data
|
||||
@@ -241,6 +248,7 @@ Response:
|
||||
```
|
||||
|
||||
#### 2. Get Processing Status
|
||||
|
||||
```http
|
||||
GET /api/v1/status/{video_id}
|
||||
|
||||
@@ -253,6 +261,7 @@ Response:
|
||||
```
|
||||
|
||||
#### 3. Get Detection Results
|
||||
|
||||
```http
|
||||
GET /api/v1/results/{video_id}
|
||||
|
||||
@@ -260,6 +269,7 @@ Response: See "Sample Detection Results" below
|
||||
```
|
||||
|
||||
#### 4. List All Videos
|
||||
|
||||
```http
|
||||
GET /api/v1/videos
|
||||
|
||||
@@ -279,24 +289,26 @@ Response:
|
||||
### Internal API Calls (Frontend)
|
||||
|
||||
**Upload Request**:
|
||||
|
||||
```typescript
|
||||
const formData = new FormData()
|
||||
formData.append("file", file)
|
||||
formData.append("speed_kmh", "30")
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
formData.append('speed_kmh', '30');
|
||||
|
||||
const response = await fetch(`${API_URL}/upload`, {
|
||||
method: "POST",
|
||||
body: formData
|
||||
})
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
});
|
||||
|
||||
const result = await response.json()
|
||||
const result = await response.json();
|
||||
// Returns: { video_id, filename, message, status }
|
||||
```
|
||||
|
||||
**Results Request**:
|
||||
|
||||
```typescript
|
||||
const response = await fetch(`${API_URL}/results/${videoId}`)
|
||||
const detectionData: DetectionData = await response.json()
|
||||
const response = await fetch(`${API_URL}/results/${videoId}`);
|
||||
const detectionData: DetectionData = await response.json();
|
||||
```
|
||||
|
||||
---
|
||||
@@ -304,13 +316,15 @@ const detectionData: DetectionData = await response.json()
|
||||
## 🔄 WebSocket Protocol
|
||||
|
||||
### Connection
|
||||
|
||||
```javascript
|
||||
const ws = new WebSocket(`ws://localhost:8000/api/v1/ws/${videoId}`)
|
||||
const ws = new WebSocket(`ws://localhost:8000/api/v1/ws/${videoId}`);
|
||||
```
|
||||
|
||||
### Message Types
|
||||
|
||||
#### 1. Status Update
|
||||
|
||||
```json
|
||||
{
|
||||
"type": "status",
|
||||
@@ -321,6 +335,7 @@ const ws = new WebSocket(`ws://localhost:8000/api/v1/ws/${videoId}`)
|
||||
```
|
||||
|
||||
#### 2. Progress Update
|
||||
|
||||
```json
|
||||
{
|
||||
"type": "progress",
|
||||
@@ -332,6 +347,7 @@ const ws = new WebSocket(`ws://localhost:8000/api/v1/ws/${videoId}`)
|
||||
```
|
||||
|
||||
#### 3. Completion
|
||||
|
||||
```json
|
||||
{
|
||||
"type": "complete",
|
||||
@@ -348,6 +364,7 @@ const ws = new WebSocket(`ws://localhost:8000/api/v1/ws/${videoId}`)
|
||||
```
|
||||
|
||||
#### 4. Error
|
||||
|
||||
```json
|
||||
{
|
||||
"type": "error",
|
||||
@@ -357,6 +374,7 @@ const ws = new WebSocket(`ws://localhost:8000/api/v1/ws/${videoId}`)
|
||||
```
|
||||
|
||||
#### 5. Heartbeat
|
||||
|
||||
```json
|
||||
{
|
||||
"type": "heartbeat"
|
||||
@@ -451,10 +469,10 @@ const ws = new WebSocket(`ws://localhost:8000/api/v1/ws/${videoId}`)
|
||||
{ "type": "progress", "progress": 50, "message": "Processing frame 600/1200", "unique_potholes": 12, "total_detections": 134 }
|
||||
|
||||
// 5. Completion
|
||||
{
|
||||
"type": "complete",
|
||||
"status": "completed",
|
||||
"progress": 100,
|
||||
{
|
||||
"type": "complete",
|
||||
"status": "completed",
|
||||
"progress": 100,
|
||||
"message": "Processing completed successfully",
|
||||
"summary": {
|
||||
"unique_potholes": 18,
|
||||
@@ -469,28 +487,28 @@ const ws = new WebSocket(`ws://localhost:8000/api/v1/ws/${videoId}`)
|
||||
|
||||
```typescript
|
||||
type DetectionData = {
|
||||
video_id: string
|
||||
video_id: string;
|
||||
video_info: {
|
||||
fps: number // 30.0
|
||||
width: number // 1920
|
||||
height: number // 1080
|
||||
total_frames: number // 1200
|
||||
}
|
||||
fps: number; // 30.0
|
||||
width: number; // 1920
|
||||
height: number; // 1080
|
||||
total_frames: number; // 1200
|
||||
};
|
||||
summary: {
|
||||
unique_potholes: number // 18
|
||||
total_detections: number // 245
|
||||
total_frames: number // 1200
|
||||
detection_rate: number // 12.25
|
||||
}
|
||||
unique_potholes: number; // 18
|
||||
total_detections: number; // 245
|
||||
total_frames: number; // 1200
|
||||
detection_rate: number; // 12.25
|
||||
};
|
||||
frames: Array<{
|
||||
frame_id: number
|
||||
frame_id: number;
|
||||
potholes: Array<{
|
||||
pothole_id: number
|
||||
bbox: { x1: number; y1: number; x2: number; y2: number }
|
||||
confidence: number
|
||||
}>
|
||||
}>
|
||||
}
|
||||
pothole_id: number;
|
||||
bbox: { x1: number; y1: number; x2: number; y2: number };
|
||||
confidence: number;
|
||||
}>;
|
||||
}>;
|
||||
};
|
||||
```
|
||||
|
||||
---
|
||||
@@ -500,6 +518,7 @@ type DetectionData = {
|
||||
### Backend Issues
|
||||
|
||||
**Model Not Loading**
|
||||
|
||||
```bash
|
||||
# Check model path
|
||||
ls models/pothole-detector.pt
|
||||
@@ -509,6 +528,7 @@ python -c "from ultralytics import YOLO; print('OK')"
|
||||
```
|
||||
|
||||
**CUDA/GPU Issues**
|
||||
|
||||
```bash
|
||||
# Check CUDA availability
|
||||
python -c "import torch; print(torch.cuda.is_available())"
|
||||
@@ -518,6 +538,7 @@ self.pothole_model = YOLO("models/pothole-detector.pt", device='cpu')
|
||||
```
|
||||
|
||||
**WebSocket Connection Failed**
|
||||
|
||||
- Ensure CORS is properly configured
|
||||
- Check firewall settings for port 8000
|
||||
- Verify WebSocket URL matches backend
|
||||
@@ -525,6 +546,7 @@ self.pothole_model = YOLO("models/pothole-detector.pt", device='cpu')
|
||||
### Frontend Issues
|
||||
|
||||
**Video Not Playing**
|
||||
|
||||
```typescript
|
||||
// Check browser console for errors
|
||||
// Ensure video MIME type is supported
|
||||
@@ -532,6 +554,7 @@ self.pothole_model = YOLO("models/pothole-detector.pt", device='cpu')
|
||||
```
|
||||
|
||||
**Bounding Boxes Not Showing**
|
||||
|
||||
```typescript
|
||||
// Check canvas dimensions match video
|
||||
// Verify detection data structure
|
||||
@@ -539,6 +562,7 @@ self.pothole_model = YOLO("models/pothole-detector.pt", device='cpu')
|
||||
```
|
||||
|
||||
**Progress Not Updating**
|
||||
|
||||
```typescript
|
||||
// Check WebSocket connection status
|
||||
// Verify video_id matches between upload and WS
|
||||
@@ -548,12 +572,14 @@ self.pothole_model = YOLO("models/pothole-detector.pt", device='cpu')
|
||||
### Performance Optimization
|
||||
|
||||
**Slow Processing**
|
||||
|
||||
- Use GPU acceleration (CUDA)
|
||||
- Reduce video resolution
|
||||
- Lower frame rate
|
||||
- Adjust confidence thresholds
|
||||
|
||||
**High Memory Usage**
|
||||
|
||||
```python
|
||||
# Limit thread pool workers
|
||||
executor = ThreadPoolExecutor(max_workers=2)
|
||||
@@ -582,6 +608,4 @@ pothole_tracker = defaultdict(lambda: deque(maxlen=10))
|
||||
- Add authentication for production deployments
|
||||
- Use HTTPS/WSS in production
|
||||
|
||||
|
||||
|
||||
**Built with FastAPI, YOLO, React, and shadcn/ui**
|
||||
**Built with FastAPI, YOLO, React, and shadcn/ui**
|
||||
|
||||
Reference in New Issue
Block a user