Skip to content

Commit

Permalink
Convert points to float on CVAT import instead of in _import_shape
Browse files Browse the repository at this point in the history
  • Loading branch information
Bobronium committed Jul 25, 2024
1 parent 292e1c4 commit 8965996
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 57 deletions.
2 changes: 0 additions & 2 deletions cvat/apps/dataset_manager/bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,6 @@ def _import_shape(self, shape, parent_label_id=None):
self.soft_attribute_import and attrib.name not in CVAT_INTERNAL_ATTRIBUTES
)
]
_shape['points'] = list(map(float, _shape['points']))
_shape['elements'] = [self._import_shape(element, label_id) for element in _shape.get('elements', [])]

return _shape
Expand All @@ -561,7 +560,6 @@ def _import_track(self, track, parent_label_id=None):
for attrib in shape['attributes']
if self._get_mutable_attribute_id(label_id, attrib.name)
]
shape['points'] = list(map(float, shape['points']))

return _track

Expand Down
110 changes: 55 additions & 55 deletions cvat/apps/dataset_manager/formats/cvat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1223,33 +1223,33 @@ def load_anno(file_object, annotations):
shape_element['elements'] = []

if el.tag == 'box':
shape_element['points'].append(el.attrib['xtl'])
shape_element['points'].append(el.attrib['ytl'])
shape_element['points'].append(el.attrib['xbr'])
shape_element['points'].append(el.attrib['ybr'])
shape_element['points'].append(float(el.attrib['xtl']))
shape_element['points'].append(float(el.attrib['ytl']))
shape_element['points'].append(float(el.attrib['xbr']))
shape_element['points'].append(float(el.attrib['ybr']))
elif el.tag == 'ellipse':
shape_element['points'].append(el.attrib['cx'])
shape_element['points'].append(el.attrib['cy'])
shape_element['points'].append("{:.2f}".format(float(el.attrib['cx']) + float(el.attrib['rx'])))
shape_element['points'].append("{:.2f}".format(float(el.attrib['cy']) - float(el.attrib['ry'])))
shape_element['points'].append(float(el.attrib['cx']))
shape_element['points'].append(float(el.attrib['cy']))
shape_element['points'].append(float("{:.2f}".format(float(el.attrib['cx']) + float(el.attrib['rx']))))
shape_element['points'].append(float("{:.2f}".format(float(el.attrib['cy']) - float(el.attrib['ry']))))
elif el.tag == 'cuboid':
shape_element['points'].append(el.attrib['xtl1'])
shape_element['points'].append(el.attrib['ytl1'])
shape_element['points'].append(el.attrib['xbl1'])
shape_element['points'].append(el.attrib['ybl1'])
shape_element['points'].append(el.attrib['xtr1'])
shape_element['points'].append(el.attrib['ytr1'])
shape_element['points'].append(el.attrib['xbr1'])
shape_element['points'].append(el.attrib['ybr1'])

shape_element['points'].append(el.attrib['xtl2'])
shape_element['points'].append(el.attrib['ytl2'])
shape_element['points'].append(el.attrib['xbl2'])
shape_element['points'].append(el.attrib['ybl2'])
shape_element['points'].append(el.attrib['xtr2'])
shape_element['points'].append(el.attrib['ytr2'])
shape_element['points'].append(el.attrib['xbr2'])
shape_element['points'].append(el.attrib['ybr2'])
shape_element['points'].append(float(el.attrib['xtl1']))
shape_element['points'].append(float(el.attrib['ytl1']))
shape_element['points'].append(float(el.attrib['xbl1']))
shape_element['points'].append(float(el.attrib['ybl1']))
shape_element['points'].append(float(el.attrib['xtr1']))
shape_element['points'].append(float(el.attrib['ytr1']))
shape_element['points'].append(float(el.attrib['xbr1']))
shape_element['points'].append(float(el.attrib['ybr1']))

shape_element['points'].append(float(el.attrib['xtl2']))
shape_element['points'].append(float(el.attrib['ytl2']))
shape_element['points'].append(float(el.attrib['xbl2']))
shape_element['points'].append(float(el.attrib['ybl2']))
shape_element['points'].append(float(el.attrib['xtr2']))
shape_element['points'].append(float(el.attrib['ytr2']))
shape_element['points'].append(float(el.attrib['xbr2']))
shape_element['points'].append(float(el.attrib['ybr2']))
else:
for pair in el.attrib['points'].split(';'):
shape_element['points'].extend(map(float, pair.split(',')))
Expand Down Expand Up @@ -1282,39 +1282,39 @@ def load_anno(file_object, annotations):
shape['rotation'] = float(el.attrib.get('rotation', 0))

if el.tag == 'box':
shape['points'].append(el.attrib['xtl'])
shape['points'].append(el.attrib['ytl'])
shape['points'].append(el.attrib['xbr'])
shape['points'].append(el.attrib['ybr'])
shape['points'].append(float(el.attrib['xtl']))
shape['points'].append(float(el.attrib['ytl']))
shape['points'].append(float(el.attrib['xbr']))
shape['points'].append(float(el.attrib['ybr']))
elif el.tag == 'ellipse':
shape['points'].append(el.attrib['cx'])
shape['points'].append(el.attrib['cy'])
shape['points'].append("{:.2f}".format(float(el.attrib['cx']) + float(el.attrib['rx'])))
shape['points'].append("{:.2f}".format(float(el.attrib['cy']) - float(el.attrib['ry'])))
shape['points'].append(float(el.attrib['cx']))
shape['points'].append(float(el.attrib['cy']))
shape['points'].append(float("{:.2f}".format(float(el.attrib['cx']) + float(el.attrib['rx']))))
shape['points'].append(float("{:.2f}".format(float(el.attrib['cy']) - float(el.attrib['ry']))))
elif el.tag == 'mask':
shape['points'] = el.attrib['rle'].split(',')
shape['points'].append(el.attrib['left'])
shape['points'].append(el.attrib['top'])
shape['points'].append("{}".format(int(el.attrib['left']) + int(el.attrib['width']) - 1))
shape['points'].append("{}".format(int(el.attrib['top']) + int(el.attrib['height']) - 1))
shape['points'] = list(map(float, el.attrib['rle'].split(',')))
shape['points'].append(float(el.attrib['left']))
shape['points'].append(float(el.attrib['top']))
shape['points'].append(float("{}".format(int(el.attrib['left']) + int(el.attrib['width']) - 1)))
shape['points'].append(float("{}".format(int(el.attrib['top']) + int(el.attrib['height']) - 1)))
elif el.tag == 'cuboid':
shape['points'].append(el.attrib['xtl1'])
shape['points'].append(el.attrib['ytl1'])
shape['points'].append(el.attrib['xbl1'])
shape['points'].append(el.attrib['ybl1'])
shape['points'].append(el.attrib['xtr1'])
shape['points'].append(el.attrib['ytr1'])
shape['points'].append(el.attrib['xbr1'])
shape['points'].append(el.attrib['ybr1'])

shape['points'].append(el.attrib['xtl2'])
shape['points'].append(el.attrib['ytl2'])
shape['points'].append(el.attrib['xbl2'])
shape['points'].append(el.attrib['ybl2'])
shape['points'].append(el.attrib['xtr2'])
shape['points'].append(el.attrib['ytr2'])
shape['points'].append(el.attrib['xbr2'])
shape['points'].append(el.attrib['ybr2'])
shape['points'].append(float(el.attrib['xtl1']))
shape['points'].append(float(el.attrib['ytl1']))
shape['points'].append(float(el.attrib['xbl1']))
shape['points'].append(float(el.attrib['ybl1']))
shape['points'].append(float(el.attrib['xtr1']))
shape['points'].append(float(el.attrib['ytr1']))
shape['points'].append(float(el.attrib['xbr1']))
shape['points'].append(float(el.attrib['ybr1']))

shape['points'].append(float(el.attrib['xtl2']))
shape['points'].append(float(el.attrib['ytl2']))
shape['points'].append(float(el.attrib['xbl2']))
shape['points'].append(float(el.attrib['ybl2']))
shape['points'].append(float(el.attrib['xtr2']))
shape['points'].append(float(el.attrib['ytr2']))
shape['points'].append(float(el.attrib['xbr2']))
shape['points'].append(float(el.attrib['ybr2']))
elif el.tag == 'skeleton':
pass
else:
Expand Down

0 comments on commit 8965996

Please sign in to comment.