Overview
Renders precise polygon boundaries around detected objects using their segmentation data. Automatically adapts line thickness based on image size and supports custom color schemes for visual distinction between different object classes.Function Signature
Parameters
Input image to draw polygons on. Must be a valid BGR image array.
Detections object containing segmentation data. Each detection must have a ‘segments’ attribute with polygon coordinates.
Line thickness for polygon outlines in pixels. If None, automatically calculated based on image dimensions. Range: [1-50]. Default is adaptive (typically 1-6).
List of BGR color tuples to override default colors. Colors are cycled through unique class_ids in order of appearance. Each tuple should be (B, G, R) with values [0-255]. If None, uses default ColorManager colors.
Returns
Image with polygon outlines drawn. Modifies the input image in-place and returns the same array reference.
Examples
Error Handling
This function may raise the following exceptions:
- AssertionError: If image is not a numpy array.
- AttributeError: If detections don’t contain segments data.
- ValueError: If polygon coordinates are invalid or out of bounds.
Notes
- Modifies the input image in-place for memory efficiency
- Polygon coordinates are automatically converted to integer format for OpenCV
- Line thickness is adaptively calculated based on image size when not specified
- Colors are assigned consistently based on class_id to maintain visual coherence
- Requires segmentation model outputs (not just bounding boxes)