gitmyhub

ai-trafic-signal-optimization-

★ 47 updated 27d ago

An educational prototype that uses computer vision to count vehicles in a video feed and automatically adjusts traffic light timings, giving more green time to busier lanes.

PythonYOLOv8FlaskMongoDBsetup: moderatecomplexity 3/5

This is an educational prototype for an AI-driven traffic signal control system. The project uses computer vision to count vehicles on a video feed and then adjusts traffic light timing based on how congested each lane is. Rather than fixed timed cycles, the system tries to give more green time to the busiest lanes.

The vehicle counting relies on YOLOv8, a widely used object detection model that can identify cars, trucks, and other vehicles in video frames. A Python backend processes a traffic video file, counts vehicles per lane by dividing the frame into regions, and then calculates signal timings. A machine learning model trained on synthetic data predicts congestion levels, returning a rating of low, medium, or high. There is also a basic emergency vehicle detection feature: if the YOLO model identifies something labeled as an ambulance, fire truck, or police vehicle, the system can switch to a green corridor mode that clears the path.

All traffic counts, signal timings, and prediction history are stored in a MongoDB database. A web dashboard, served directly from the Python backend, shows live vehicle counts, the current state of a simulated four-way junction with animated traffic lights, charts of recent data, and alerts for emergency vehicle detections.

The README is clear that this is a prototype built for learning. It uses a single pre-recorded video file rather than real CCTV feeds. Lane boundaries are approximated by splitting the video frame into rough sections. The machine learning model is retrained from scratch each time the server starts, using a small synthetic dataset, which would not be appropriate for real deployment.

Setup requires Python, MongoDB running locally, and a sample traffic video file you provide. Running one Python command starts the Flask backend and serves the dashboard at a local web address.

Where it fits