SmartTraffic AI System
An advanced Edge/IoT Big Data solution designed for real-time traffic monitoring, analysis, and decision support. By leveraging state-of-the-art Computer Vision (YOLOv8) and distributed processing patterns, the system transforms raw video streams into actionable insights.
Real-time Processing
Process 30+ simultaneous RTSP streams with < 100ms latency per frame.
Big Data Ready
Handling High Volume, Velocity, and Variety of traffic data on edge infrastructure.
System Metrics
Architecture Workflow
The system follows a pipelined architecture: Acquisition → Processing → Storage → Distribution. The diagram below illustrates the data flow from camera sensors to the end-user dashboard.
Core Components
Struktur modul utama yang membangun sistem dari akuisisi data hingga penyajian.
Camera Agent
Multi-thread capture, YOLO inference, counting, stabilisasi stream.
File: app/services/camera.py
API & Views
Endpoint /api/stats, /api/history, /api/predict_traffic, /api/reset_data, /metrics, /export/csv serta halaman Dashboard & Docs.
File: app/routes.py
Data Management
Load/save stats & config, backfill, generate history, rolling window, Data Lake export.
File: app/utils.py
Database Layer
SQLite schema, batch insert, history query, prediksi berbasis DOW/Hour, agregasi lifetime.
File: app/database.py
Global State
global_stats, daftar kamera, agen aktif, lock untuk thread-safety.
File: app/globals.py
Frontend Dashboard
Peta, routing realistis, kartu statistik, editor marker.
File: app/templates/dashboard.html
Documentation UI
Sidebar, flowchart arsitektur & prediksi, 4Vs Big Data.
File: app/templates/documentation.html
Config & Models
Konfigurasi kamera & ROI, file statistik JSON, model YOLO.
Files: app/config.py, data/cctv_config.json, data/traffic_stats.json, models/yolov8l.pt
Study Case: Traffic Efficiency Analysis
This section maps the system's capabilities to the standard traffic management framework (Analysis, Identify, Design, Implementation, Evaluation).
1. Analysis & Comparison
Comparison of traffic monitoring methodologies.
| Feature | SmartTraffic AI (Edge) | Traditional Loops | Manual Survey |
|---|---|---|---|
| Cost | Low (Existing CCTV) | High (Road Works) | Medium (Labor) |
| Real-time Data | Yes (< 1s Latency) | Yes | No (Post-processing) |
| Classification | Deep Learning (Car/Motor) | Limited (Length based) | High Accuracy |
2. Identify
The system automatically identifies:
- Vehicle Types (Car vs Motorcycle) using YOLOv8 models.
- Traffic Density Levels (Smooth, Heavy, Critical).
- Camera Operational Status (Online/Offline detection).
3. Design
Mobile-first dashboard design with Glassmorphism UI. The system uses a distributed event-driven architecture to handle high-velocity data streams from multiple sensors.
4. Implementation
Deployed on Linux Edge Server (Ubuntu) running:
- Backend: Python Flask + OpenCV + Multi-threading.
- AI Engine: Ultralytics YOLOv8.
- Database: SQLite (Metadata) + JSON (Time-series).
5. Evaluation
Simultaneous processing
Historical data points
Big Data & Predictive Analytics
SmartTraffic AI leverages the 4Vs of Big Data to transform raw video streams into actionable predictive insights. The system moves beyond simple monitoring to provide "Decision Support" capabilities.
1. Volume (Scale)
Storing over 3.5 Million+ historical data points. The system accumulates granular traffic logs (vehicle counts, types, timestamps) for every active camera.
2. Velocity (Speed)
Processes 37 concurrent video streams in real-time (< 500ms latency). Data is ingested, analyzed, and visualized instantly on the dashboard.
3. Variety (Complexity)
Transforms unstructured data (CCTV Video Feeds) into structured metadata (JSON/SQL). Handles diverse inputs from various IP camera models.
4. Value (Insight)
The ultimate goal. Converts data into Traffic Predictions and routing recommendations to optimize city traffic flow.
Prediction Algorithm
The prediction engine uses a Historical Pattern Replay algorithm. It does not just guess; it calculates the Average Hourly Volume for a specific Day of Week and Hour based on all available historical data.
Example: To predict traffic for next "Monday at 08:00 AM", the system averages the traffic volume of every previous Monday at 08:00 AM recorded in the database.
Difference: Real-time vs Prediction
- Real-time Status: Based on Visual Density (0-100 score) from the camera feed right now.
- Prediction: Based on Historical Volume (Total Vehicles/Hour) calculated from past data.
// Python Implementation (Logic)
def predict_traffic(camera_id, target_date):
# 1. Extract Temporal Features
# SQLite: 0=Sunday, 1=Monday... 6=Saturday
day_of_week = target_date.strftime('%w')
target_hour = target_date.hour
# 2. Query Big Data Lake (Aggregation)
# "Calculate the average volume for this specific Day and Hour across all history"
query = """
SELECT AVG(hourly_total)
FROM (
SELECT SUM(new_count) as hourly_total
FROM traffic_history
WHERE camera_id = ? AND dow = ? AND hour = ?
GROUP BY date(timestamp)
)
"""
# 3. Apply Threshold Logic (Volume based)
avg_volume = execute(query)
if avg_volume > 2000: return "MACET TOTAL" # > 2000 vehicles/hour
if avg_volume > 1000: return "MACET" # > 1000 vehicles/hour
if avg_volume > 500: return "PADAT LANCAR"# > 500 vehicles/hour
return "LANCAR" # < 500 vehicles/hour
Key Features
Deep Learning Classification
Differentiates between Cars and Motorcycles with high precision using custom-trained YOLO models optimized for Indonesian traffic conditions.
Interactive Map Editor
Admin-only interface for managing camera locations via drag-and-drop. Includes secure authentication and real-time coordinate updates.
Data Backfill Engine
Intelligent historical data synthesis to fill gaps in records, ensuring continuous trend analysis even after system downtimes.
API Reference
The system exposes a RESTful API for data consumption and integration.
/api/stats
Retrieves real-time traffic statistics for all active cameras.
{
"status": "success",
"sources": {
"cam_1": {
"name": "Simpang Dago",
"current_count": 45,
"accumulated_count": 1250,
"status": "online"
}
}
}
/api/edit_camera
Admin
Updates camera configuration including geolocation coordinates.
{
"username": "admin",
"password": "...",
"id": "cam_1",
"lat": -6.914744,
"lng": 107.609810
}
Data Models
Core data structures used for persistence and configuration.
Traffic History (SQL)
| Column | Type | Description |
|---|---|---|
| id | INTEGER | Primary Key |
| camera_id | TEXT | Source Identifier |
| timestamp | REAL | Unix Timestamp |
| total_count | INTEGER | Aggregate Volume |
Camera Config (JSON)
"name": "Location Name",
"source": "rtsp://...",
"lat": -6.9175,
"lng": 107.6191,
"roi": [0, 0, 1920, 1080]
}