Detection zones are the quadrilateral regions in the camera frame that correspond to each directional lane at the intersection. Every vehicle detected by YOLOv8 is assigned to one of four zones — Norte, Sur, Este, or Oeste — based on where its bounding-box centroid falls. Vehicles whose centroids do not land inside any zone are labelledDocumentation 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.
other and excluded from the traffic counts used for signal-phase decisions.
Default zone definitions
Zones are defined inTrafficCamera.__init__() inside video_processor.py as normalized coordinate arrays. Each value is in the range 0.0–1.0 relative to the frame dimensions, so the same zone definition works regardless of the actual pixel resolution of the video feed.
traffic_dron_view.mp4) and the bundled YouTube live stream. For a different camera angle, mounting height, or intersection geometry, the coordinates must be updated.
Zone color overlays
The live feed renders a colored polygon border around each zone to aid visual debugging. The overlay colors are also used for bounding boxes drawn around vehicles that have been matched to a zone.| Zone | Overlay color | BGR value |
|---|---|---|
| Norte | Amber | (255, 180, 60) |
| Sur | Cyan | (60, 200, 255) |
| Este | Green | (90, 230, 130) |
| Oeste | Purple | (200, 120, 255) |
other) are drawn with a neutral grey box (130, 130, 130).
How to tune zones for a new camera
Capture a still frame
Pause the live feed or extract a single frame from your camera source. Save it as a PNG or JPEG so you can open it in an image editor.
Identify lane corners
In the image editor, locate the four pixel corners that bound each directional lane as seen from the camera’s perspective. Note down the
(x, y) pixel coordinates for each corner.Normalize the coordinates
Convert pixel coordinates to the For example, a point at pixel
0.0–1.0 range using the frame dimensions:(427, 230) in an 854 × 480 frame normalizes to (0.50, 0.48).Vehicle assignment logic
Zone matching is performed inside_run_yolo() using OpenCV’s cv2.pointPolygonTest(). For each detected vehicle, the method computes the centroid of its bounding box and tests it against each zone polygon in order:
pointPolygonTest means the centroid is on the boundary or inside the polygon. The loop breaks on the first match, so each vehicle is counted in at most one zone.
Zones can overlap. A vehicle centroid that falls inside an overlapping region is assigned to whichever zone is tested first. The fixed iteration order is Norte → Este → Sur → Oeste, matching Python’s dict insertion order as defined in
__init__(). Design your zones to minimize overlap, particularly near the centre of the intersection.