This guide walks you from a freshly cloned repository to a live, AI-controlled traffic signal dashboard running in your browser. By the end you will have the Flask server running, a video source connected, and YOLOv8 actively counting vehicles and selecting green-light phases in real time.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Xander44-4/traffic_reducer/llms.txt
Use this file to discover all available pages before exploring further.
Clone the repository and navigate to the project
Clone the Traffic Reducer repository and change into the project root. All subsequent commands assume you are running from this directory.The project root contains the YOLO weight files (
yolov8m.pt, yolov8s.pt, yolov8n.pt) and the traffic_app/ directory with app.py and video_processor.py.Install all Python dependencies
Install every required package in one command using the provided requirements file:This installs the following packages:
Installation typically takes one to three minutes depending on your internet speed.
| Package | What it provides |
|---|---|
flask | Web server and REST API |
opencv-python | Frame capture and image processing |
ultralytics | YOLOv8 inference (also installs imageio-ffmpeg) |
yt-dlp | YouTube live stream URL extraction |
pandas | Data handling utilities |
numpy | Numerical operations and zone detection |
joblib | Alternative .pkl model loader |
scikit-learn | Pre-trained signal-phase model compatibility |
ultralytics is the largest dependency as it pulls in PyTorch.Start the Traffic Reducer server
Launch the Flask application from the project root:On macOS or Linux, use:You will see the following startup output in your terminal:The server starts in idle mode by default — the
TrafficCamera background thread is running but no video source is active yet. The YOLO model is loaded and ready; video processing begins as soon as you choose a source in the next steps.You may see
TLS or Socket error messages in the console after the server starts. These are harmless. TrafficCamera includes automatic reconnection logic that handles transient stream failures, so the system will recover without any action on your part.Open the dashboard in your browser
With the server running, open your web browser and navigate to:You will see the Traffic Reducer dashboard. The video panel shows a placeholder frame with the message “Selecciona una fuente para comenzar” because the system is in idle mode. The zone count panels (Norte, Sur, Este, Oeste) display zeroes until a video source is connected.
Choose a video source and activate AI control
-
Click the source modal button in the dashboard toolbar. A dialog appears offering two options:
- YouTube live stream — connects to the configured live traffic camera via
yt-dlpand streams it through FFmpeg. An internet connection is required. - Local video — plays
traffic_app/static/traffic_dron_view.mp4at 0.5× speed from disk, with no internet dependency.
- YouTube live stream — connects to the configured live traffic camera via
-
Select your preferred source and confirm. The
POST /set_sourceAPI endpoint switchesTrafficCamerato the chosen mode. The console will print the connection status — for YouTube mode you will see:When frames start arriving, the console will print[TrafficCamera] Stream YouTube abierto (ffmpeg pipe) — esperando primer frame...followed by frame processing logs. This confirms that YOLOv8 is actively processing frames and zone counts are being updated. -
Click “Activar Control” (or the LIVE SIMULATION MODE toggle) to enable AI decision mode. The system now calls
POST /predictwithlive_mode: trueon each cycle, appliesnp.argmaxacross the four zone counts, and sets the winning direction as the active green-light phase. The dashboard signal display updates in real time to reflect the AI decision.
What to expect
Once a source is active and AI control is enabled, the dashboard updates every second with:- Annotated video — bounding boxes colour-coded by zone (amber for Norte, cyan for Sur, green for Este, purple for Oeste), plus yellow boxes for pedestrians and red boxes for detected emergency vehicles
- Zone vehicle counts — live counts for Norte, Sur, Este, and Oeste lanes
- Active phase — the zone currently holding the green light, as decided by the majority-rule algorithm
- Priority flags — a pedestrian or emergency indicator when an override is in effect