[Datumaro] Add rounding for coordinates (#1970)

* Add rounding for annotation coordinates

* Fix polygon area computation

* update changelog
main
zhiltsov-max 6 years ago committed by GitHub
parent 18d04ff0f4
commit 2c38cb4967
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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
-

@ -20,6 +20,9 @@ AnnotationType = Enum('AnnotationType',
'caption',
])
_COORDINATE_ROUNDING_DIGITS = 2
class Annotation:
# pylint: disable=redefined-builtin
def __init__(self, id=None, type=None, attributes=None, group=None):
@ -378,9 +381,9 @@ class _Shape(Annotation):
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)
@ -460,8 +463,8 @@ class Polygon(_Shape):
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

@ -15,13 +15,12 @@ import pycocotools.mask as mask_utils
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:
@ -308,7 +307,7 @@ class _InstancesConverter(_TaskConverter):
'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:
@ -336,7 +335,6 @@ class _KeypointsConverter(_InstancesConverter):
'supercategory': cast(label_cat.parent, str, ''),
'keypoints': [],
'skeleton': [],
}
if point_categories is not None:

Loading…
Cancel
Save