Adaptive Traffic Signal Management (ATSM)
YOLOv8 + SORT — Vehicle counting, line crossing, and adaptive timing
Demo

Quickstart
py -3.12 -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -r requirements.txt
python car_counter.py
Download ZIP
How it works
- YOLOv8 detects vehicles in the ROI.
- SORT (Kalman + IOU) maintains stable IDs across frames.
- Line crossing increments a unique vehicle count.
- Red timer reduces when congestion exceeds a threshold.
Configuration and CLI
Use config.yaml
for defaults and override via CLI:
# Default
python car_counter.py
# Custom config
python car_counter.py --config my_config.yaml
# Override key params
python car_counter.py --video Media/cars3.mp4 --weights Weights/yolov8l.pt \
--line 150 360 1200 360 --threshold 15 --normal 70 --reduced 40 --cooldown 15 --conf 0.4
Detailed explanation
Detection
Ultralytics YOLOv8 runs on the masked region-of-interest to reduce false positives and compute cost.
-
Weights:
Weights/yolov8n.pt
(fast) oryolov8l.pt
(more accurate). -
Classes counted:
car
,truck
,motorbike
,bus
. - Confidence threshold configurable via
--conf
.
Tracking (SORT)
Kalman filter predicts positions; IOU-based matching assigns detections to tracks with unique IDs.
-
Key params:
max_age
,min_hits
,iou_threshold
. - Stable IDs prevent double-counting across adjacent frames.
Counting
When a tracked center crosses the configured line window, the ID is marked counted once per cycle.
- Line coordinates:
count_line = [x1, y1, x2, y2]
. - Change via config or
--line x1 y1 x2 y2
.
Adaptive timing
If the unique count exceeds the threshold, the red timer reduces for the current cycle with a simple cooldown to prevent oscillation.
- Threshold:
car_count_threshold
. -
Timers:
normal_red_timer
,reduced_red_timer
. - Cooldown:
cooldown_duration
.
Tips & troubleshooting
-
Use
yolov8n.pt
for CPU or low-spec GPUs; upgrade toyolov8l.pt
for accuracy checks. -
Adjust
--conf
if you see false positives/negatives. - Tune SORT params for your traffic scene density/speed.
-
Replace
Media/mask.png
for a new intersection layout.
Cite this work
Please cite the repository if you use or build upon it.
@software{jambhale_atsm_2025,
author = {Jambhale, Anuj},
title = {Adaptive Traffic Signal Management (ATSM): Vehicle Counting with YOLOv8 + SORT},
year = {2025},
url = {https://github.com/jambhaleAnuj/Traffic_signal_counter_using_car_count_python},
doi = {10.5281/zenodo.16903140}
}