diff --git a/cvat/apps/annotation/coco.py b/cvat/apps/annotation/coco.py index 7317f097a371..3f5ffc996002 100644 --- a/cvat/apps/annotation/coco.py +++ b/cvat/apps/annotation/coco.py @@ -364,11 +364,12 @@ def match_frame(frame_info, filename): for ann in anns: group = 0 label_name = labels[ann['category_id']] + polygons = [] if 'segmentation' in ann: - polygons = [] # polygon if ann['iscrowd'] == 0: - polygons = ann['segmentation'] + # filter non-empty polygons + polygons = [polygon for polygon in ann['segmentation'] if polygon] # mask else: if isinstance(ann['segmentation']['counts'], list): @@ -395,3 +396,18 @@ def match_frame(frame_info, filename): attributes=[], group=group, )) + + if not polygons and 'bbox' in ann and isinstance(ann['bbox'], list): + xtl = ann['bbox'][0] + ytl = ann['bbox'][1] + xbr = xtl + ann['bbox'][2] + ybr = ytl + ann['bbox'][3] + annotations.add_shape(annotations.LabeledShape( + type='rectangle', + frame=frame_number, + label=label_name, + points=[xtl, ytl, xbr, ybr], + occluded=False, + attributes=[], + group=group, + )) diff --git a/cvat/apps/engine/models.py b/cvat/apps/engine/models.py index d856b9d768ee..5118afdea284 100644 --- a/cvat/apps/engine/models.py +++ b/cvat/apps/engine/models.py @@ -280,7 +280,7 @@ class FloatArrayField(models.TextField): separator = "," def from_db_value(self, value, expression, connection): - if value is None: + if value is None or not value: return value return [float(v) for v in value.split(self.separator)]