Beyond counting vehicles to decide which lane gets the green light, Traffic Reducer monitors every processed frame for two safety-critical conditions: the presence of pedestrians in the intersection area and the appearance of emergency vehicles exhibiting characteristic light signatures. When either condition is detected it is surfaced immediately to the dashboard and can override normal signal-phase logic, ensuring that human safety and emergency response always take precedence over queue-length optimisation.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.
Pedestrian detection
COCO class 0 (person) is included in the YOLOv8 inference call alongside vehicle classes, but persons are handled on a separate path inside _run_yolo(). Instead of being tested against zone polygons, each person detection increments a dedicated counter:
traffic_state['pedestrians'] and returned by the /stats endpoint. The frontend displays the raw count at all times and labels the current priority as "PEATONES" when the pedestrian count exceeds 5, indicating a crossing situation that should hold or redirect the active signal phase.
Pedestrian bounding boxes are drawn in bright blue-white (255, 200, 0) on the annotated frame overlay so operators can visually verify detections in the dashboard video feed.
Emergency vehicle detection
Emergency vehicle identification is performed by_looks_like_emergency(), a method that analyses the HSV color distribution of a vehicle’s bounding-box crop to detect active emergency lighting. It is only called for class 5 (bus) and class 7 (truck) detections that have already passed the confidence threshold — smaller vehicle classes are excluded because their bounding boxes are rarely large enough to contain reliable lighting information.
Full method source
Detection logic breakdown
Step 1 — Minimum bounding-box area Small bounding boxes produce too few pixels for reliable color analysis and are rejected before any HSV computation:| Class ID | Vehicle type | Minimum area |
|---|---|---|
| 7 | Truck | 8 000 px² |
| 5 | Bus | 12 000 px² |
| Channel | HSV range(s) | Emergency threshold |
|---|---|---|
| Red | (0,130,110)→(10,255,255) and (170,130,110)→(180,255,255) | > 18 % of crop area |
| Yellow | (18,130,130)→(35,255,255) | > 22 % of crop area |
| Blue | (95,150,100)→(130,255,255) | Used in combined rule only |
True (emergency detected) if either of the following conditions holds:
red_ratio > 0.18ORyellow_ratio > 0.22— a dominant single emergency color saturates most of the vehicle crop.red_ratio > 0.07ANDblue_ratio > 0.05— a combined red-and-blue signature, characteristic of police and ambulance light bars.
Emergency flag propagation
When_looks_like_emergency() returns True for any detection in a frame, _run_yolo() sets emergency_detected = True and appends the box with the label 'emergency'. After the YOLO future resolves, the flag flows into traffic_state:
/stats endpoint exposes it as a JSON boolean:
emergency on every /stats poll (every 1 500 ms) and displays "SÍ" in red when true, labelling the active priority as "EMERGENCIA". Emergency vehicle bounding boxes are rendered with a vivid red border (0, 50, 255) at 3 px width to distinguish them clearly from ordinary vehicle detections on the video feed.
Priority hierarchy
When multiple conditions are active simultaneously, the dashboard applies the following precedence (highest to lowest):- Emergency vehicle detected — takes absolute precedence; the
"EMERGENCIA"label and red indicator are shown regardless of pedestrian count or vehicle counts. - Pedestrian crossing (count > 5) — overrides the normal queue-based priority label with
"PEATONES". - Majority-rule lane selection — standard operation when neither override condition is active.