Spaces:
Sleeping
title: RR Traffic Analysis System
emoji: π
colorFrom: blue
colorTo: green
sdk: docker
app_port: 7860
Real-time Vehicle Detection and Traffic Analysis System for Malaysia Rest & Recreation (R&R) Stops
Description of the system:
- using RF-Detr Base model (roboflow's) for detecting and classifying vehicles entering and exiting the R&R stops from surveillance footage (video file or live camera feed) into sedan, SUV, pickup, van, motorcycle, bus or truck.
- track (using bytetrack) and count (once the vehicle crosses a user-defined line), and calculate the people flow (using the data of the min and max seat capacity of each vehicle type). E,g,. Sedan - min = 1, max = 5.
- after user uploaded or selected the surveillance footage, user will be prompt to draw the line on first frame extracted.
- The data is logged, saved to Firebase, and displayed in the dashboard.
- Include: key performance indicators that summarise the current state (including an estimated on-site people range (expressed as a bounded interval) and net vehicle movement derived from inbound and outbound counts), visualisation of the historical data in charts, and might include a prediction on the people flow in the future
- The annotated vehicle dataset is using one found from Roboflow (imbalanced classes, will improve in the future), include the 7 classes: sedan, SUV, pickup, van, motorcycle, bus or truck.
- Will deployed using Flask and Firebase Realtime Database.
Seat-Capacity Mapping:
| Vehicle Type | Seat Capacity |
|---|---|
| Sedan | 1β5 |
| SUV | 1β8 |
| Pickup | 1β6 |
| Van | 1β15 |
| Bus | 1β50 |
| Truck | 1β3 |
| Motorcycle | 1β2 |
Project Structure
rr-traffic-analysis-system/
βββ app/
β βββ __init__.py # Flask app factory
β βββ config.py # App configuration (Secret keys, Roboflow API Key)
β βββ models.py # Data Classes (e.g., class VehicleLog, class TrafficStat)
β βββ routes/
β β βββ __init__.py
β β βββ dashboard.py # Renamed from 'main.py' for clarity
β β βββ setup.py # Renamed from 'config.py' to avoid confusion with app/config.py
β βββ services/
β β βββ __init__.py
β β βββ video_processor.py # The RF-DETR & ByteTrack Logic (Threaded)
β β βββ firebase_service.py # Handles 'logging' and 'real-time' DB pushes
β β βββ processing_service.py
β βββ static/
β β βββ css/
β β β βββ style.css
β β βββ js/
β β βββ dashboard.js # Charts.js logic for polling Firebase
β β βββ setup_canvas.js # Renamed: Logic for drawing the line over the video frame
β βββ templates/
β β βββ base.html
β β βββ dashboard.html
β β βββ setup.html
β βββ utils/
β βββ __init__.py
β βββ math_utils.py
β
βββ model_data/ # Store .pt weights
βββ uploads/ # Store temp user videos here
βββ output/ # Processed videos
βββ requirements.txt
βββ .env # Store ROBOFLOW_API_KEY and FIREBASE_CREDENTIALS here
βββ run.py
Plan
Proposed UI/UX: "The Analyst Workbench" Instead of a static dashboard, treat the page as a workspace with two states.
Layout Strategy
Left Sidebar (Collapsible): This replaces the "Setup Page." It holds the inputs for Video Source and Camera Role.
Center Stage (The Player): A large video container that toggles between "Raw Video" (for drawing lines) and "Processed Stream" (for viewing results).
Bottom/Right Panel: The Analytics (Charts, Logs) that update as the video plays.
State 1: Configuration Mode (Default on Load)
Sidebar: Open. User sees "Upload Video" and "Camera Role: Entry/Exit".
Center: Shows the First Frame of the video.
Action: User draws the line directly on this frame.
Button: A large "Start Analysis" button is visible.
State 2: Analysis Mode (After Clicking Start)
Sidebar: Automatically collapses or switches to "Job Status" (Progress bar).
Center: Switches to the Processed Video Feed (showing bounding boxes).
Action: The user watches the analysis.
Button: "Stop/Edit" button appears to return to State 1