How karthikrao117/adaptive-traffic-controller-with-yolo-object-detection works
Project type and purpose
• This is a specialized computer-vision pipeline application (an open-source tool) that processes one or more video streams in real time.
• It detects and tracks vehicles in four lanes using YOLOv7, counts them per lane, and then runs an Adaptive Traffic Control System (ATCS) algorithm to decide which lane gets the next green signal.
File structure
• Top-level scripts:
• yolo_video.py – orchestrates the pipeline: reads input, runs detection, tracking, counting, visualization, ATCS.
• atcs.py – encapsulates the ATCS optimization logic (round-robin + starvation avoidance + congestion prioritization).
• runDetections.py – wraps YOLOv7 inference on a frame batch.
• input_retrieval.py – handles threaded video capture using imutils’ FileVideoStream.
• input_videos/ – sample MP4 inputs.
• yolo-coco/ holds model assets: coco.names, yolov7-tiny.cfg, yolov7-tiny.weights.
• No separate frontend/backend – the entire pipeline lives in Python scripts.
README insights
• Highlights performance optimizations: threaded frame reading (imutils), skip-frame technique, CPU-only compatibility.
• Describes the detection→tracking→counting→ATCS decision loop in detail.
Main components and interactions
a. Video Ingestion Module
• Component: input_retrieval.py (imutils FileVideoStream)
• Role: spawn thread(s), read frames into a buffer/queue.
b. Pre-Processing Module
c. YOLO Inference Engine
• runDetections.py + yolo-coco assets
d. Tracking & Counting Module
• In yolo_video.py: use frame-to-frame center-point distance over last 10 frames to track IDs; count new vehicles per lane.
e. ATCS Optimization Module
• atcs.py: ingest counts + starvation metrics; apply round-robin with congestion weighting; output next green-signal decision and duration.
f. Output & Visualization Module
Architectural patterns & design principles
• Pipeline pattern: discrete stages (Ingest → Pre-process → Inference → Post-process → Decision → Output) connected by in-memory queues.
• Threading for I/O decoupling (frame reader thread vs. main processing loop).
• Modular scripts: each responsibility isolated (configuration, inference, ATCS logic).
• No persistent storage required; counts and states live in memory each cycle.
7. ATCS outputs “Next Green Lane & Duration.”
8. Loop back to Pre-Processing for the next decision cycle.
Detail and clarity
• Skip-frame optimization: annotate the Pre-Processing step with “skip N frames before inference.”
• Configurable parameters: confidence threshold, NMS threshold, skip-frame count, max cycle time.