Skip to content

Commit 1ca384c

Browse files
committed
updates to account for edge case polygons
1 parent c62d83e commit 1ca384c

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

labelbox/data/annotation_types/geometry/mask.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ def draw(self,
9898

9999
def _extract_polygons_from_contours(self, contours: List) -> MultiPolygon:
100100
contours = map(np.squeeze, contours)
101-
polygons = map(Polygon, contours)
101+
filtered_contours = filter(lambda contour: len(contour) > 2, contours)
102+
polygons = map(Polygon, filtered_contours)
102103
return MultiPolygon(polygons)
103104

104105
def create_url(self, signer: Callable[[bytes], str]) -> str:

labelbox/data/serialization/coco/instance_dataset.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ def mask_to_coco_object_annotation(annotation: ObjectAnnotation, annot_idx: int,
2121
# This is going to fill any holes into the multipolygon
2222
# If you need to support holes use the panoptic data format
2323
shapely = annotation.value.shapely.simplify(1).buffer(0)
24+
if shapely.is_empty:
25+
shapely = annotation.value.shapely.simplify(1).buffer(0.01)
2426
xmin, ymin, xmax, ymax = shapely.bounds
2527
# Iterate over polygon once or multiple polygon for each item
2628
area = shapely.area

0 commit comments

Comments
 (0)