diff --git a/supervision/dataset/formats/coco.py b/supervision/dataset/formats/coco.py index 723ad463..c8b73758 100644 --- a/supervision/dataset/formats/coco.py +++ b/supervision/dataset/formats/coco.py @@ -118,8 +118,9 @@ def _mask_has_holes(mask: np.ndarray) -> bool: def _mask_has_multiple_segments(mask: np.ndarray) -> bool: - mask_uint8 = mask.astype(np.uint8) - number_of_labels, _ = cv2.connectedComponents(mask_uint8, connectivity=4) + mask_uint8 = mask.astype(np.uint8) + labels = np.zeros_like(mask_uint8, dtype=np.int32) + number_of_labels, _ = cv2.connectedComponents(mask_uint8, labels, connectivity=4) return number_of_labels > 2 diff --git a/test/dataset/formats/test_coco.py b/test/dataset/formats/test_coco.py index 11085a90..6be0fa2c 100644 --- a/test/dataset/formats/test_coco.py +++ b/test/dataset/formats/test_coco.py @@ -476,7 +476,7 @@ def test_build_coco_class_index_mapping( ], DoesNotRaise(), ), # no segmentation mask - ( + ( Detections( xyxy=np.array([[0, 0, 4, 5]], dtype=np.float32), class_id=np.array([0], dtype=int), @@ -565,7 +565,7 @@ def test_build_coco_class_index_mapping( ) ], DoesNotRaise(), - ), # segmentation mask in single component, with holes in mask, expects RLE mask + ), # seg mask in single component, with holes in mask, expects RLE mask ], ) def test_detections_to_coco_annotations(