Overview
Renders defined zones as filled polygons with optional borders, displaying zone names, detection counts, and total entry statistics. Automatically adapts text size and thickness based on image resolution for optimal visibility across different image sizes.Function Signature
Parameters
Input image to annotate. Must be 3-channel BGR format. zone_manager: ZoneManager instance containing polygon zones with associated metadata. Must have ‘zones’ attribute containing Zone objects with polygon, color, name, and count attributes.
Fill opacity for zone polygons. Range: [0.0, 1.0]. Default is 0.3 (30% transparency).
Pixel thickness of zone borders. If None, automatically calculated based on image size. Range: [1, 20]. Default adapts to image resolution.
Whether to display current detection count in each zone. Shows both current count and total entries if available. Default is True.
Whether to display zone names as text labels. Default is True.
Scale factor for text size. If None, automatically calculated based on image resolution. Range: [0.3, 2.0]. Default adapts to image size.
Thickness of text stroke in pixels. If None, automatically calculated based on image size. Range: [1, 5]. Default adapts to font scale.
RGB color tuple for text labels. If None, uses white (255, 255, 255). Range: [0, 255] per channel.
RGB color tuple for text background. If None, uses black (0, 0, 0). Range: [0, 255] per channel.
Opacity of text background rectangles. Range: [0.0, 1.0]. Default is 0.7 (70% opacity).
Vertical position for count display relative to zone. Options: ‘center’ (zone centroid), ‘top’ (above zone), ‘bottom’ (below zone). Default is ‘center’.
Whether to fill zone polygons with semi-transparent color. Default is True.
Whether to draw zone polygon borders. Default is True.
Returns
Annotated image with zones visualized. Modifies input image in-place and returns the modified array.
Examples
Error Handling
This function may raise the following exceptions:
- AssertionError: If image is not a numpy ndarray.
- AttributeError: If zone_manager lacks ‘zones’ attribute or zones lack required properties (polygon, color, name, current_count).
- IndexError: If zone polygon coordinates are outside image boundaries during text positioning calculations.
Notes
- Modifies the input image in-place for memory efficiency
- Text size and thickness automatically adapt to image resolution when not specified
- Zone colors are taken from individual Zone objects in the zone_manager
- Count display shows format “Count: X” or “Count: X (Total: Y)” when total_entered available
- Text positioning uses zone polygon centroid with automatic adjustment for top/bottom modes
- Semi-transparent overlays are created using OpenCV’s addWeighted for smooth blending
- Polygon rendering uses anti-aliased lines for smooth appearance
- Text background rectangles include padding calculated from adaptive parameters
- Processing time scales with number of zones and image resolution
- Memory usage is optimized through in-place image modification
- Overlay operations create temporary image copies for transparency blending
- Text rendering involves multiple OpenCV operations per label