GodfreyOwino/vehicle-detection
0
๐ Vehicle Detection & Tracking API
A FastAPI-based REST API that provides intelligent vehicle detection and tracking using YOLO v8. Features include real-world traffic simulation through video looping, SQLite database storage, and comprehensive analytics.
๐ Features
- AI-Powered Detection: YOLO v8 for accurate vehicle detection
- Multi-Vehicle Tracking: Track cars, trucks, buses, motorcycles, and bicycles
- Real-World Simulation: Loop videos multiple times to simulate extended traffic periods
- Database Storage: SQLite database for persistent detection storage
- Direction Detection: Track vehicles entering and exiting
- Analytics Dashboard: Comprehensive traffic statistics and insights
- Batch Processing: Process multiple sessions simultaneously
๐ง API Endpoints
Core Endpoints
POST /upload- Upload video with loop configurationGET /sessions- Get all processing sessionsGET /sessions/{session_id}- Get session statisticsGET /sessions/{session_id}/detections- Get detection detailsGET /database/stats- Overall database statisticsDELETE /sessions/{session_id}- Delete session and data
Usage Examples
Upload Video with Loops
import requests
files = {'file': open('traffic_video.mp4', 'rb')}
params = {'loops': 5, 'session_name': 'Morning Rush Hour'}
response = requests.post('https://your-space.hf.space/upload',
files=files, params=params)
print(response.json())
Get Session Statistics
pythonresponse = requests.get('https://your-space.hf.space/sessions/session-id')
stats = response.json()
print(f"Total Detections: {stats['total_detections']}")
print(f"Vehicles In: {stats['vehicles_in']}")
print(f"Vehicles Out: {stats['vehicles_out']}")
๐๏ธ Database Schema
Vehicle Detections
session_id: Links to processing session
vehicle_id: Unique tracker ID
vehicle_type: car, truck, bus, motorcycle, bicycle
direction: coming_in, going_out
loop_number: Which simulation loop (1-20)
timestamp: Exact detection time
confidence: Detection confidence score
Processing Sessions
session_id: Unique session identifier
filename: Original video filename
total_loops: Number of simulation loops
status: processing, completed, error
created_at: Session start time
๐ฏ Real-World Simulation
The loop feature allows you to simulate extended traffic periods:
1 Loop: Process video once (normal mode)
5 Loops: Simulate 5x traffic volume
10 Loops: Extended simulation for pattern analysis
20 Loops: Maximum simulation for comprehensive data
Each loop generates independent detection events, perfect for:
Traffic pattern analysis
Peak hour simulation
Long-term trend analysis
Capacity planning
๐ Analytics Features
Real-time Tracking: Live detection counting
Vehicle Classification: Automatic type detection
Direction Analysis: Entry vs exit tracking
Time-based Insights: Temporal traffic patterns
Historical Data: Complete detection history
Export Capabilities: JSON data export
๐ ๏ธ Technical Stack
Backend: FastAPI + SQLAlchemy
AI Model: YOLO v8 (Ultralytics)
Database: SQLite
Computer Vision: OpenCV
Deployment: Docker + Hugging Face Spaces
๐ Getting Started
Upload Video: Use /upload endpoint with your traffic video
Set Loops: Configure simulation loops (1-20)
Monitor Progress: Check /sessions/{id} for status
View Results: Get detections via /sessions/{id}/detections
Analyze Data: Use /database/stats for insights
๐ Use Cases
Traffic Analysis: Understand traffic patterns and volume
Urban Planning: Data for infrastructure decisions
Security Monitoring: Vehicle tracking and counting
Research: Transportation and mobility studies
Smart Cities: Real-time traffic management
Built with โค๏ธ for intelligent transportation systems!
