imgutils.detect.visual
- Overview:
This module provides functionality for visualizing object detection results on images. It includes tools for drawing bounding boxes, labels, and confidence scores on detected objects.
The main function
detection_visualize()
can be used to visualize detection results from various object detection models, with customizable appearance settings like font size, padding, and label visibility.See
imgutils.detect.head.detect_heads()
andimgutils.detect.person.detect_person()
for examples.
detection_visualize
- imgutils.detect.visual.detection_visualize(image: str | PathLike | bytes | bytearray | BinaryIO | Image, detection: List[Tuple[Tuple[float, float, float, float], str, float]], labels: List[str] | None = None, text_padding: int = 6, fontsize: int = 12, max_short_edge_size: int | None = None, fp=None, no_label: bool = False)[source]
Visualize object detection results by drawing bounding boxes and labels on an image.
- Parameters:
image (ImageTyping) – Input image to visualize detections on. Can be a PIL Image, numpy array, or path to image file.
detection (List[Tuple[Tuple[float, float, float, float], str, float]]) – List of detection results, each containing ((x0, y0, x1, y1), label, confidence_score). Coordinates should be in pixels, not normalized.
labels (Optional[List[str]]) – List of predefined labels. If None, labels will be extracted from detection results.
text_padding (int) – Padding around label text in pixels.
fontsize (int) – Font size for label text.
max_short_edge_size (Optional[int]) – Maximum size of shortest image edge. If specified, image will be resized while maintaining aspect ratio.
fp (matplotlib.font_manager.FontProperties or None) – Font properties for matplotlib font. Only used if matplotlib is available.
no_label (bool) – If True, suppresses drawing of labels.
- Returns:
PIL Image with visualized detection results.
- Return type:
PIL.Image.Image
- Examples::
>>> from imgutils.detect import detect_heads, detection_visualize >>> >>> image = load_image("path/to/image.jpg") >>> detections = detect_heads(image) >>> visualized = detection_visualize(image, detections) >>> visualized.save("output.png")
See
imgutils.detect.head.detect_heads()
andimgutils.detect.person.detect_person()
for examples.