From bcf543776a2d4d16d0155505b487c46db4b43989 Mon Sep 17 00:00:00 2001 From: Anastasia Yasakova Date: Wed, 22 Mar 2023 16:13:57 +0200 Subject: [PATCH] Fix mask annotations in CVAT format (#5905) ### Motivation and context Fixed #5828 - Fixed mask annotations in CVAT format - Updated documentation ### How has this been tested? ### Checklist - [x] I submit my changes into the `develop` branch - [ ] I have added a description of my changes into the [CHANGELOG](https://github.com/opencv/cvat/blob/develop/CHANGELOG.md) file - [ ] I have updated the documentation accordingly - [ ] I have added tests to cover my changes - [ ] I have linked related issues (see [GitHub docs]( https://help.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword)) - [ ] I have increased versions of npm packages if it is necessary ([cvat-canvas](https://github.com/opencv/cvat/tree/develop/cvat-canvas#versioning), [cvat-core](https://github.com/opencv/cvat/tree/develop/cvat-core#versioning), [cvat-data](https://github.com/opencv/cvat/tree/develop/cvat-data#versioning) and [cvat-ui](https://github.com/opencv/cvat/tree/develop/cvat-ui#versioning)) ### License - [ ] I submit _my code changes_ under the same [MIT License]( https://github.com/opencv/cvat/blob/develop/LICENSE) that covers the project. Feel free to contact the maintainers if that's a concern. --------- Co-authored-by: Boris Sekachev --- CHANGELOG.md | 1 + cvat/apps/dataset_manager/formats/cvat.py | 12 ++++++------ site/content/en/docs/manual/advanced/xml_format.md | 11 +++++++++-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ea7fb084c56..6e438bbaf839 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Invalid mask when running automatic annotation on a task () - Cloud storage content listing when the manifest name contains special characters () +- Width and height in CVAT dataset format mask annotations () ### Security - TDB diff --git a/cvat/apps/dataset_manager/formats/cvat.py b/cvat/apps/dataset_manager/formats/cvat.py index 854659774bb8..c3a7f708aeec 100644 --- a/cvat/apps/dataset_manager/formats/cvat.py +++ b/cvat/apps/dataset_manager/formats/cvat.py @@ -795,8 +795,8 @@ def dump_labeled_shapes(shapes, is_skeleton=False): ("rle", f"{list(int (v) for v in shape.points[:-4])}"[1:-1]), ("left", f"{int(shape.points[-4])}"), ("top", f"{int(shape.points[-3])}"), - ("width", f"{int(shape.points[-2] - shape.points[-4])}"), - ("height", f"{int(shape.points[-1] - shape.points[-3])}"), + ("width", f"{int(shape.points[-2] - shape.points[-4]) + 1}"), + ("height", f"{int(shape.points[-1] - shape.points[-3]) + 1}"), ])) elif shape.type != 'skeleton': dump_data.update(OrderedDict([ @@ -933,8 +933,8 @@ def dump_shape(shape, element_shapes=None, label=None): ("rle", f"{list(int (v) for v in shape.points[:-4])}"[1:-1]), ("left", f"{int(shape.points[-4])}"), ("top", f"{int(shape.points[-3])}"), - ("width", f"{int(shape.points[-2] - shape.points[-4])}"), - ("height", f"{int(shape.points[-1] - shape.points[-3])}"), + ("width", f"{int(shape.points[-2] - shape.points[-4]) + 1}"), + ("height", f"{int(shape.points[-1] - shape.points[-3]) + 1}"), ])) elif shape.type == "cuboid": dump_data.update(OrderedDict([ @@ -1293,8 +1293,8 @@ def load_anno(file_object, annotations): shape['points'] = el.attrib['rle'].split(',') shape['points'].append(el.attrib['left']) shape['points'].append(el.attrib['top']) - shape['points'].append("{}".format(int(el.attrib['left']) + int(el.attrib['width']))) - shape['points'].append("{}".format(int(el.attrib['top']) + int(el.attrib['height']))) + shape['points'].append("{}".format(int(el.attrib['left']) + int(el.attrib['width']) - 1)) + shape['points'].append("{}".format(int(el.attrib['top']) + int(el.attrib['height']) - 1)) elif el.tag == 'cuboid': shape['points'].append(el.attrib['xtl1']) shape['points'].append(el.attrib['ytl1']) diff --git a/site/content/en/docs/manual/advanced/xml_format.md b/site/content/en/docs/manual/advanced/xml_format.md index 8efab34c1828..1c983e3d8275 100644 --- a/site/content/en/docs/manual/advanced/xml_format.md +++ b/site/content/en/docs/manual/advanced/xml_format.md @@ -38,7 +38,7 @@ In annotation mode each image tag has `width` and `height` attributes for the sa