diff --git a/CHANGELOG.md b/CHANGELOG.md index 0da60518f6b7..e50226d91103 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - ### Fixed +- File names in LabelMe format export are no longer truncated ([#1259](https://github.com/opencv/cvat/issues/1259)) - `occluded` and `z_order` annotation attributes are now correctly passed to Datumaro ([#1271](https://github.com/opencv/cvat/pull/1271)) - Annotation-less tasks now can be exported as empty datasets in COCO ([#1277](https://github.com/opencv/cvat/issues/1277)) - Frame name matching for video annotations import - diff --git a/cvat/apps/annotation/labelme.py b/cvat/apps/annotation/labelme.py index 0128ca739226..baacb388ef01 100644 --- a/cvat/apps/annotation/labelme.py +++ b/cvat/apps/annotation/labelme.py @@ -107,17 +107,17 @@ def dump_frame_anno(frame_annotation): return ET.tostring(root_elem, encoding='unicode', pretty_print=True) def dump_as_labelme_annotation(file_object, annotations): + import os.path as osp from zipfile import ZipFile, ZIP_DEFLATED with ZipFile(file_object, 'w', compression=ZIP_DEFLATED) as output_zip: for frame_annotation in annotations.group_by_frame(): xml_data = dump_frame_anno(frame_annotation) - filename = frame_annotation.name - filename = filename[ : filename.rfind('.')] + '.xml' + filename = osp.splitext(frame_annotation.name)[0] + '.xml' output_zip.writestr(filename, xml_data) def parse_xml_annotations(xml_data, annotations, input_zip): - from cvat.apps.annotation.coco import mask_to_polygon + from datumaro.util.mask_tools import mask_to_polygons from io import BytesIO from lxml import etree as ET import numpy as np @@ -229,7 +229,7 @@ def parse_attributes(attributes_string): mask = input_zip.read(osp.join(_MASKS_DIR, mask_file)) mask = np.asarray(Image.open(BytesIO(mask)).convert('L')) mask = (mask != 0) - polygons = mask_to_polygon(mask) + polygons = mask_to_polygons(mask) for polygon in polygons: ann_items.append(annotations.LabeledShape( diff --git a/cvat/apps/engine/tests/test_rest_api.py b/cvat/apps/engine/tests/test_rest_api.py index d959f71c5b51..f3da0410623c 100644 --- a/cvat/apps/engine/tests/test_rest_api.py +++ b/cvat/apps/engine/tests/test_rest_api.py @@ -2655,6 +2655,15 @@ def _get_initial_annotation(annotation_format): "points": [20.0, 0.1, 10, 3.22, 4, 7, 10, 30, 1, 2, 4.44, 5.55], "type": "polygon", "occluded": True + }, + { + "frame": 2, + "label_id": task["labels"][1]["id"], + "group": 1, + "attributes": [], + "points": [4, 7, 10, 30, 4, 5.55], + "type": "polygon", + "occluded": False }] tags_wo_attrs = [{ @@ -2711,6 +2720,12 @@ def _get_initial_annotation(annotation_format): elif annotation_format == "MOT CSV 1.0": annotations["tracks"] = rectangle_tracks_wo_attrs + elif annotation_format == "LabelMe ZIP 3.0 for images": + annotations["shapes"] = rectangle_shapes_with_attrs + \ + rectangle_shapes_wo_attrs + \ + polygon_shapes_wo_attrs + \ + polygon_shapes_with_attrs + return annotations response = self._get_annotation_formats(annotator)