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)