Skip to content

Commit

Permalink
Support for complex polygon import
Browse files Browse the repository at this point in the history
  • Loading branch information
JBWilkie committed Jan 6, 2025
1 parent 314ec61 commit 8ec70d0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
6 changes: 3 additions & 3 deletions darwin/importer/formats/coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def parse_annotation(
return [dt.make_polygon(category["name"], paths)]
elif isinstance(segmentation, list):
paths = segmentation if isinstance(segmentation[0], list) else [segmentation]
polygons = []
point_paths = []
for path in paths:
point_path = []
points = iter(path)
Expand All @@ -180,8 +180,8 @@ def parse_annotation(
point_path.append({"x": x, "y": y})
except StopIteration:
break
polygons.append(dt.make_polygon(category["name"], point_path))
return polygons
point_paths.append(point_path)
return [dt.make_polygon(category["name"], point_paths)]
else:
return []

Expand Down
13 changes: 7 additions & 6 deletions tests/darwin/importer/formats/import_coco_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def test_parse_annotation_single_polygon():
assert path[2] == {"x": 20, "y": 20}


def test_parse_annotation_multiple_polygons():
"""Test parsing segmentation with multiple polygons"""
def test_parse_annotation_multiple_paths():
"""Test parsing segmentation with multiple paths in a single polygon"""
annotation = {
"segmentation": [
[10, 10, 20, 10, 20, 20, 10, 20],
Expand All @@ -41,16 +41,17 @@ def test_parse_annotation_multiple_polygons():

result = parse_annotation(annotation, category_lookup)

assert len(result) == 2
assert all(isinstance(r, dt.Annotation) for r in result)
assert all(r.annotation_class.name == "test_class" for r in result)
assert len(result) == 1
assert isinstance(result[0], dt.Annotation)
assert result[0].annotation_class.name == "test_class"
assert len(result[0].data["paths"]) == 2

path1 = result[0].data["paths"][0]
assert len(path1) == 4
assert path1[0] == {"x": 10, "y": 10}
assert path1[2] == {"x": 20, "y": 20}

path2 = result[1].data["paths"][0]
path2 = result[0].data["paths"][1]
assert len(path2) == 4
assert path2[0] == {"x": 30, "y": 30}
assert path2[2] == {"x": 40, "y": 40}
Expand Down

0 comments on commit 8ec70d0

Please sign in to comment.