Skip to content

Commit

Permalink
COCO: load bbox as rectangle if segmentation field is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Zhavoronkov committed Oct 18, 2019
1 parent bec77ea commit 4a4c8df
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
20 changes: 18 additions & 2 deletions cvat/apps/annotation/coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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,
))
2 changes: 1 addition & 1 deletion cvat/apps/engine/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]

Expand Down

0 comments on commit 4a4c8df

Please sign in to comment.