CoolFace
Apppublic

GodfreyOwino/vehicle-detection

sourceHugging Facemitupdated 1y agoView on Hugging Face
0likes
App README

๐Ÿš— 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 configuration
  • โ€”GET /sessions - Get all processing sessions
  • โ€”GET /sessions/{session_id} - Get session statistics
  • โ€”GET /sessions/{session_id}/detections - Get detection details
  • โ€”GET /database/stats - Overall database statistics
  • โ€”DELETE /sessions/{session_id} - Delete session and data

Usage Examples

Upload Video with Loops
python
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!