Skip to content

Commit

Permalink
added polygon and complex polygon tests with bounding boxes
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristofferEdlund committed Oct 16, 2023
1 parent a9018b2 commit b21b144
Showing 1 changed file with 88 additions and 4 deletions.
92 changes: 88 additions & 4 deletions tests/darwin/exporter/formats/export_darwin_1_0_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,84 @@ def test_complete_annotation_file(self):
{"x": 529.8140000000002, "y": 426.5896},
]

annotation_class = dt.AnnotationClass(name="test", annotation_type="polygon")
annotation = dt.Annotation(annotation_class=annotation_class, data={"path": polygon_path}, subs=[])

annotation_file = dt.AnnotationFile(
path=Path("test.json"),
filename="test.json",
annotation_classes=[annotation_class],
annotations=[annotation],
image_height=1080,
image_width=1920,
image_url="https://darwin.v7labs.com/image.jpg",
)

assert _build_json(annotation_file) == {
"image": {
"seq": None,
"width": 1920,
"height": 1080,
"filename": "test.json",
"original_filename": "test.json",
"url": "https://darwin.v7labs.com/image.jpg",
"thumbnail_url": None,
"path": None,
"workview_url": None,
},
"annotations": [{"polygon": {"path": polygon_path}, "name": "test", "slot_names": []}],
"dataset": "None",
}

def test_complex_polygon(self):
polygon_path = [
[{"x": 230.06, "y": 174.04}, {"x": 226.39, "y": 170.36}, {"x": 224.61, "y": 166.81}],
[{"x": 238.98, "y": 171.69}, {"x": 236.97, "y": 174.04}, {"x": 238.67, "y": 174.04}],
[
{"x": 251.75, "y": 169.77},
{"x": 251.75, "y": 154.34},
{"x": 251.08, "y": 151.84},
{"x": 249.25, "y": 150.01},
],
]

annotation_class = dt.AnnotationClass(name="test", annotation_type="complex_polygon")
annotation = dt.Annotation(annotation_class=annotation_class, data={"paths": polygon_path}, subs=[])

annotation_file = dt.AnnotationFile(
path=Path("test.json"),
filename="test.json",
annotation_classes=[annotation_class],
annotations=[annotation],
image_height=1080,
image_width=1920,
image_url="https://darwin.v7labs.com/image.jpg",
)

assert _build_json(annotation_file) == {
"image": {
"seq": None,
"width": 1920,
"height": 1080,
"filename": "test.json",
"original_filename": "test.json",
"url": "https://darwin.v7labs.com/image.jpg",
"thumbnail_url": None,
"path": None,
"workview_url": None,
},
"annotations": [{"complex_polygon": {"path": polygon_path}, "name": "test", "slot_names": []}],
"dataset": "None",
}


def test_polygon_annotation_file_with_bbox(self):
polygon_path = [
{"x": 534.1440000000002, "y": 429.0896},
{"x": 531.6440000000002, "y": 428.4196},
{"x": 529.8140000000002, "y": 426.5896},
]

bounding_box = {"x": 557.66,
"y": 428.98,
"w": 160.76,
Expand Down Expand Up @@ -91,11 +169,11 @@ def test_complete_annotation_file(self):
"path": None,
"workview_url": None,
},
"annotations": [{"polygon": {"path": polygon_path}, "name": "test", "slot_names": []}],
"annotations": [{"polygon": {"path": polygon_path}, "name": "test", "slot_names": [], "bounding_box": bounding_box}],
"dataset": "None",
}

def test_complex_polygon(self):
def test_complex_polygon_with_bbox(self):
polygon_path = [
[{"x": 230.06, "y": 174.04}, {"x": 226.39, "y": 170.36}, {"x": 224.61, "y": 166.81}],
[{"x": 238.98, "y": 171.69}, {"x": 236.97, "y": 174.04}, {"x": 238.67, "y": 174.04}],
Expand All @@ -107,8 +185,14 @@ def test_complex_polygon(self):
],
]

bounding_box = {"x": 557.66,
"y": 428.98,
"w": 160.76,
"h": 315.3
}

annotation_class = dt.AnnotationClass(name="test", annotation_type="complex_polygon")
annotation = dt.Annotation(annotation_class=annotation_class, data={"paths": polygon_path}, subs=[])
annotation = dt.Annotation(annotation_class=annotation_class, data={"paths": polygon_path, "bounding_box": bounding_box}, subs=[])

annotation_file = dt.AnnotationFile(
path=Path("test.json"),
Expand All @@ -132,6 +216,6 @@ def test_complex_polygon(self):
"path": None,
"workview_url": None,
},
"annotations": [{"complex_polygon": {"path": polygon_path}, "name": "test", "slot_names": []}],
"annotations": [{"complex_polygon": {"path": polygon_path}, "name": "test", "slot_names": [], "bounding_box": bounding_box}],
"dataset": "None",
}

0 comments on commit b21b144

Please sign in to comment.