Traffic Reducer exposes eight HTTP endpoints onDocumentation 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.
http://127.0.0.1:5000. All endpoints accept and return JSON (except /video_feed, which streams MJPEG frames). Start the server with python traffic_app/app.py before making any requests.
GET /
Serves the main web dashboard as an HTML page. Open this URL in a browser to access the full Traffic Reducer interface with live camera feed, signal phase display, and control buttons. No parameters. Returns: HTML page (text/html).
GET /video_feed
Streams the annotated camera feed as a continuous MJPEG response. Each frame is JPEG-encoded and includes zone polygon overlays (Norte, Sur, Este, Oeste), bounding boxes for detected vehicles and pedestrians, and red highlights for emergency vehicles. Content-Type:multipart/x-mixed-replace; boundary=frame
Embed the stream directly in an HTML page:
GET /stats
Returns the current traffic state captured from the live camera or local video. All counts reflect the most recent completed YOLOv8 inference pass. No request body.Vehicle count detected in the North zone.
Vehicle count detected in the South zone.
Vehicle count detected in the East zone.
Vehicle count detected in the West zone.
Total number of pedestrian detections across all zones.
true if an emergency vehicle (bus class 5 or truck class 7 with red/yellow/blue color signature) is currently detected in the frame.Current active signal phase label. Possible values:
"NORTE", "SUR", "ESTE", "OESTE", "INIT".The direction with the highest vehicle count (e.g.,
"ESTE"). Returns "--" when all counts are zero.Index of the priority direction:
0 = Norte, 1 = Sur, 2 = Este, 3 = Oeste. Returns -1 when all counts are zero.Current video source mode. One of
"idle", "youtube", or "local".POST /predict
Determines the recommended winning signal phase usingnp.argmax() on the four vehicle counts and returns the result. In manual mode, the counts you supply in the request body are used directly. In live mode, the counts are read from the camera’s latest YOLOv8 inference result, and the winning phase is automatically applied to the camera display via set_phase().
The endpoint requires
modelo_semaforo_ia.pkl to be successfully loaded at startup — it returns 500 with {"error": "Modelo no disponible"} if the model is absent, even though the argmax computation itself does not call model.predict(). Verify MODEL_PATH in app.py points to the correct file to pass this guard.When
true, reads vehicle counts from the live camera instead of the request body. All direction fields are ignored.Vehicle count for the North direction. Used only when
live_mode is false.Vehicle count for the South direction. Used only when
live_mode is false.Vehicle count for the East direction. Used only when
live_mode is false.Vehicle count for the West direction. Used only when
live_mode is false.Winning phase index:
0 = Norte, 1 = Sur, 2 = Este, 3 = Oeste. When all counts are zero, returns 0.The Norte, Sur, Este, and Oeste counts (as floats) that were actually used in the prediction.
POST /set_source
Switches the active video source. Closing the current source (YouTube ffmpeg pipe or localcv2.VideoCapture) happens immediately; the new source opens on the next loop iteration of the background thread.
Request body (JSON):
Target source mode. Must be
"youtube" or "local". The value "idle" cannot be set through this endpoint.{"mode": "<applied_mode>"}
Errors:
400ifmodeis not"youtube"or"local".400ifmodeis"local"andtraffic_app/static/traffic_dron_view.mp4does not exist on disk.
POST /set_speed
Sets the playback speed multiplier for local video. The value is clamped to a minimum of0.05 to prevent a zero or negative interval. Has no effect on the YouTube stream.
Request body (JSON):
Speed multiplier.
1.0 = normal speed, 2.0 = double speed, 0.5 = half speed. Clamped to ≥ 0.05.{"speed": <applied_value>} — the clamped value that was actually applied.
GET /source_status
Returns the current video source mode and whether the local video file exists on disk. The dashboard calls this endpoint on load to decide whether to enable the VIDEO LOCAL button. No request body.Current source mode:
"idle", "youtube", or "local".true if traffic_app/static/traffic_dron_view.mp4 exists on the server’s filesystem.GET /simulate
Returns random vehicle counts between0 and 80 for each direction. Useful for testing the dashboard and the /predict endpoint without a live camera feed or local video file.
No request body.
Random vehicle count for North (0–80).
Random vehicle count for South (0–80).
Random vehicle count for East (0–80).
Random vehicle count for West (0–80).