Skip to content

Commit

Permalink
Add polygon point count checks (#975)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiltsov-max authored and nmanovic committed Dec 18, 2019
1 parent 4de8be7 commit e9f1db0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cvat/apps/annotation/coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ def insert_annotation_data(image, category_map, segm_id, obj, result_annotation)
new_anno['image_id'] = image.frame
new_anno['iscrowd'] = 0
new_anno['segmentation'] = obj['points']
if len(obj['points'][0]) < 6:
raise Exception("Unable to export frame #{}: "
"a polygon has too few points ({})".format(
image.frame, len(obj['points'][0])))
area, bbox = polygon_area_and_bbox(obj['points'], image.height, image.width)
new_anno['area'] = float(np.sum(area))
new_anno['bbox'] = bbox
Expand Down Expand Up @@ -367,6 +371,10 @@ def load(file_object, annotations):
group = group_idx

for polygon in polygons:
if len(polygon) < 6:
raise Exception("Unable to import annotation #{}: "
"a polygon has too few points ({})".format(
ann['id'], len(polygon)))
annotations.add_shape(annotations.LabeledShape(
type='polygon',
frame=frame_number,
Expand Down
2 changes: 2 additions & 0 deletions datumaro/datumaro/components/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ class PolygonObject(ShapeObject):
# pylint: disable=redefined-builtin
def __init__(self, points=None,
label=None, id=None, attributes=None, group=None):
if points is not None:
assert len(points) % 2 == 0 and 3 <= len(points) // 2, "Wrong polygon points: %s" % points
super().__init__(type=AnnotationType.polygon,
points=points, label=label,
id=id, attributes=attributes, group=group)
Expand Down

0 comments on commit e9f1db0

Please sign in to comment.