From 7382984474ccaca35d86688fd2fa12e405184fda Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 1 Oct 2024 13:29:51 +0200 Subject: [PATCH] Fix zero-mask plotting bug (#16588) --- ultralytics/utils/plotting.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ultralytics/utils/plotting.py b/ultralytics/utils/plotting.py index 823eadc2..16f1cb88 100644 --- a/ultralytics/utils/plotting.py +++ b/ultralytics/utils/plotting.py @@ -805,11 +805,14 @@ class Annotator: Function for drawing segmented object in bounding box shape. Args: - mask (list): masks data list for instance segmentation area plotting - mask_color (RGB): mask foreground color - label (str): Detection label text - txt_color (RGB): text color + mask (np.ndarray): A 2D array of shape (N, 2) containing the contour points of the segmented object. + mask_color (tuple): RGB color for the contour and label background. + label (str, optional): Text label for the object. If None, no label is drawn. + txt_color (tuple): RGB color for the label text. """ + if mask.size == 0: # no masks to plot + return + cv2.polylines(self.im, [np.int32([mask])], isClosed=True, color=mask_color, thickness=2) text_size, _ = cv2.getTextSize(label, 0, self.sf, self.tf)