Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Ai-1263] darwin py converts polygon annotations incorrectly #686

Merged
29 changes: 23 additions & 6 deletions darwin/exporter/formats/darwin_1_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,33 @@ def _build_image_annotation(annotation: Annotation, skip_slots: bool = False) ->


def _build_legacy_annotation_data(annotation_class: AnnotationClass, data: DictFreeForm) -> DictFreeForm:
if annotation_class.annotation_type == "complex_polygon":
data["path"] = data["paths"]
del data["paths"]
return {"complex_polygon": data}
else:
return {annotation_class.annotation_type: data}
v1_data = {}
polygon_annotation_mappings = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the use of a mapping, stylistically.

"complex_polygon": "paths",
"polygon": "path"
}

if annotation_class.annotation_type in polygon_annotation_mappings:
key = polygon_annotation_mappings[annotation_class.annotation_type]
v1_data[annotation_class.annotation_type] = {"path": data.get(key)}

elif annotation_class.annotation_type == "tag":
v1_data["tag"] = {}

elif annotation_class.annotation_type == "bounding_box":
v1_data["bounding_box"] = data

if "bounding_box" in data and annotation_class.annotation_type != "bounding_box":
# Poygons and complex polygons usually have attached bounding_box annotations
v1_data["bounding_box"] = data["bounding_box"]

return v1_data


def _build_metadata(annotation_file: AnnotationFile) -> DictFreeForm:
if len(annotation_file.slots) > 0 and annotation_file.slots[0].metadata:
return {"metadata": annotation_file.slots[0].metadata}
else:
return {}