Skip to content

[Datumaro] Add rounding for coordinates #1970

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

Merged
merged 4 commits into from
Aug 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
-

### Changed
-
- Shape coordinates are rounded to 2 digits in dumped annotations (<https://github.com/opencv/cvat/pull/1970>)
- COCO format does not produce polygon points for bbox annotations (<https://github.com/opencv/cvat/pull/1953>)

### Deprecated
-
Expand Down
13 changes: 8 additions & 5 deletions datumaro/datumaro/components/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
'caption',
])

_COORDINATE_ROUNDING_DIGITS = 2


class Annotation:
# pylint: disable=redefined-builtin
def __init__(self, id=None, type=None, attributes=None, group=None):
Expand Down Expand Up @@ -378,9 +381,9 @@ def __init__(self, type, points=None, label=None, z_order=None,
id=None, attributes=None, group=None):
super().__init__(id=id, type=type,
attributes=attributes, group=group)
if points is None:
points = []
self._points = list(points)
if points is not None:
points = [round(p, _COORDINATE_ROUNDING_DIGITS) for p in points]
self._points = points

if label is not None:
label = int(label)
Expand Down Expand Up @@ -460,8 +463,8 @@ def __init__(self, points=None, label=None,
def get_area(self):
import pycocotools.mask as mask_utils

_, _, w, h = self.get_bbox()
rle = mask_utils.frPyObjects([self.points], h, w)
x, y, w, h = self.get_bbox()
rle = mask_utils.frPyObjects([self.points], y + h, x + w)
area = mask_utils.area(rle)[0]
return area

Expand Down
8 changes: 3 additions & 5 deletions datumaro/datumaro/plugins/coco_format/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
import datumaro.util.annotation_tools as anno_tools
import datumaro.util.mask_tools as mask_tools
from datumaro.components.converter import Converter
from datumaro.components.extractor import (DEFAULT_SUBSET_NAME, AnnotationType,
Points)
from datumaro.components.extractor import (_COORDINATE_ROUNDING_DIGITS,
DEFAULT_SUBSET_NAME, AnnotationType, Points)
from datumaro.util import cast, find, str_to_bool

from .format import CocoPath, CocoTask


SegmentationMode = Enum('SegmentationMode', ['guess', 'polygons', 'mask'])

class _TaskConverter:
Expand Down Expand Up @@ -308,7 +307,7 @@ def convert_instance(self, instance, item):
'category_id': cast(ann.label, int, -1) + 1,
'segmentation': segmentation,
'area': float(area),
'bbox': list(map(float, bbox)),
'bbox': [round(float(n), _COORDINATE_ROUNDING_DIGITS) for n in bbox],
'iscrowd': int(is_crowd),
}
if 'score' in ann.attributes:
Expand Down Expand Up @@ -336,7 +335,6 @@ def save_categories(self, dataset):
'supercategory': cast(label_cat.parent, str, ''),
'keypoints': [],
'skeleton': [],

}

if point_categories is not None:
Expand Down