check for empty mask

This commit is contained in:
magda skoczen
2024-05-16 09:20:26 +02:00
parent 1e8ee47db2
commit 3ee72e38c3
+4 -1
View File
@@ -109,7 +109,8 @@ def coco_annotations_to_detections(
def _mask_has_holes(mask: np.ndarray) -> bool:
mask_uint8 = mask.astype(np.uint8)
_, hierarchy = cv2.findContours(mask_uint8, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_SIMPLE)
_, hierarchy = cv2.findContours(
mask_uint8, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_SIMPLE)
parent_countour_index = 3
for h in hierarchy[0]:
if h[parent_countour_index] != -1:
@@ -118,6 +119,8 @@ def _mask_has_holes(mask: np.ndarray) -> bool:
def _mask_has_multiple_segments(mask: np.ndarray) -> bool:
if mask.size == 0:
return False
mask_uint8 = mask.astype(np.uint8)
number_of_labels, _ = cv2.connectedComponents(mask_uint8, connectivity=4)
return number_of_labels > 2