How imamh0ssain/traffic-management-system-bangladesh works
1. Repository purpose
This is a video analytics application for traffic monitoring. Its core function is to read prerecorded video, detect 11 vehicle classes with a custom YOLOv8 model, track objects across frames with ByteTrack, and produce both a live UI view and an annotated output video.
2. Top-level execution boundary
run.py is the main entry point. It branches into two operating modes:
- GUI mode for interactive monitoring
- CLI mode for running inference on a video file without the interface
This is the main runtime boundary separating user interaction from the processing pipeline.
3. Processing pipeline
The central runtime flow lives in src/pipeline.py. It coordinates the end-to-end video stream processing and is described as multi-threaded, with separate stages for:
- frame capture
- detection
- tracking / post-processing
This indicates the system is designed around streaming throughput rather than batch processing.
4. Detection subsystem
src/detector.py encapsulates YOLOv8 inference using an exported ONNX model. The repository includes both:
- models/yolov8n.onnx
- models/yolov8n.engine
The ONNX path is the primary architecture shown in the README, while the TensorRT engine suggests optional accelerated deployment on supported hardware.
5. Tracking subsystem
src/tracker.py implements ByteTrack, with Kalman filter smoothing called out in the README. Its role is to assign persistent IDs to detected vehicles across frames, turning per-frame detections into tracked object trajectories and counts.
6. User interface subsystem
src/gui.py contains the PyQt5 interface. It presents the live video stream, metrics, and class counts while the pipeline runs. The GUI is not the processing core; it is a consumer of pipeline outputs and status updates.
7. Metrics and reporting
src/metrics.py is a separate subsystem for aggregating runtime statistics such as counts and performance-related values. In the architecture diagram, this sits beside tracking rather than inside detection, because its job is to summarize pipeline state for display and reporting.
8. Configuration boundary
src/config.py centralizes tunable runtime parameters such as confidence threshold, IoU threshold, and track retention settings like max_age. This makes model/pipeline behavior configurable without changing the core modules.
9. Data flow through the system
Input video comes from data/ or an arbitrary file path in CLI mode. Frames enter the pipeline, are passed to the detector, then to the tracker, then to metrics/UI rendering, and finally to the output writer. The annotated result is saved under outputs/.
10. Model and asset layout
The models/ directory is the inference asset boundary and contains the trained model artifacts. The data/ directory is input-only sample media, while outputs/ is the sink for generated annotated videos. These directories are important in a diagram as source, model, and sink zones.
11. Technology stack that materially affects architecture
The system is Python-based, uses PyQt5 for the interface, ONNX Runtime for inference, and optionally TensorRT/CUDA for acceleration. That combination explains why the architecture is split between UI, threaded pipeline, and inference/tracking components.
12. Operational shape
The application is oriented toward near-real-time monitoring, not training. The repository contains no training pipeline, database, or network service layer. The architectural focus is therefore a local, video-in/video-out processing engine with an interactive presentation layer.
Main entry points: pipeline.py Pipeline · detector.py Detector · gui.py PyQt UI · main.py Launcher
Components 16
Runtime
Entry points and operating modes
Processing
Video analysis pipeline and core subsystems
- Pipeline · Coordinates threaded video processing end to end
src/pipeline.py - Capture · Reads frames from prerecorded video input
src/pipeline.py - Detector · Runs object detection using the exported model
src/detector.py - Tracker · Assigns persistent IDs and smooths trajectories across frames
src/tracker.py - Metrics · Aggregates counts and runtime statistics for display and reporting
src/metrics.py - Post-process · Combines detections, tracks, and overlays into annotated output
src/pipeline.py - Config · Centralizes confidence, IoU, and tracking parameters
src/config.py
Presentation
Interactive monitoring interface
- PyQt UI · Live video view with metrics and class counts
src/gui.py
Assets
Input videos, model artifacts, and generated outputs
- Input videos · Sample or user-provided prerecorded video files
data - YOLOv8 ONNX · Primary inference model used by the detector
models/yolov8n.onnx - TensorRT engine · Optional accelerated deployment artifact
models/yolov8n.engine - Outputs · Annotated video files generated by the pipeline
outputs
Connections 19
- run.py → Launcher: starts · Launches the application bootstrap
- Launcher → GUI mode: interactive · Routes into the GUI workflow
- Launcher → CLI mode: batch · Routes into the command-line workflow
- GUI mode → PyQt UI: uses · GUI mode is implemented by the PyQt interface
- CLI mode → Pipeline: runs · CLI mode executes the video pipeline without the UI
- PyQt UI → Pipeline: consumes · GUI receives frames, metrics, and status from the pipeline
- Pipeline → Config: reads · Pipeline behavior is controlled by runtime configuration
- Pipeline → Capture: captures · Reads frames from input video
- Capture → Input videos: loads · Video frames come from input files or sample media
- Capture → Detector: feeds · Captured frames are sent for inference
- Detector → YOLOv8 ONNX: inference · Uses the ONNX model for detection
- Detector → TensorRT engine: optional accel · May use the TensorRT engine when available
- Detector → Tracker: detections · Detected objects are forwarded to tracking
- Tracker → Metrics: updates · Track state contributes to counts and statistics
- Tracker → Post-process: tracks · Tracked objects are passed to rendering and annotation
- Metrics → PyQt UI: displays · Metrics are shown in the live interface
- Post-process → Outputs: writes · Annotated video is written to the output directory
- Post-process → PyQt UI: renders · Annotated frames are shown in the live UI
- Pipeline → Outputs: saves · Pipeline persists the finished annotated video