From 34c88be4cd91529bc062cc4303f1a4c394bcc65c Mon Sep 17 00:00:00 2001 From: Kentaro Wada Date: Thu, 9 Jan 2020 11:43:42 +0000 Subject: [PATCH] Use shapes as list of dictionary --- labelme/app.py | 9 ++++++++- labelme/label_file.py | 20 ++++++++++---------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/labelme/app.py b/labelme/app.py index de37469..1890648 100644 --- a/labelme/app.py +++ b/labelme/app.py @@ -1011,7 +1011,14 @@ class MainWindow(QtWidgets.QMainWindow): def loadLabels(self, shapes): s = [] - for label, points, line_color, fill_color, shape_type, flags in shapes: + for shape in shapes: + label = shape['label'] + points = shape['points'] + line_color = shape['line_color'] + fill_color = shape['fill_color'] + shape_type = shape['shape_type'] + flags = shape['flags'] + shape = Shape(label=label, shape_type=shape_type) for x, y in points: shape.addPoint(QtCore.QPointF(x, y)) diff --git a/labelme/label_file.py b/labelme/label_file.py index ca756a6..25f90b8 100644 --- a/labelme/label_file.py +++ b/labelme/label_file.py @@ -21,7 +21,7 @@ class LabelFile(object): suffix = '.json' def __init__(self, filename=None): - self.shapes = () + self.shapes = [] self.imagePath = None self.imageData = None if filename is not None: @@ -82,17 +82,17 @@ class LabelFile(object): ) lineColor = data['lineColor'] fillColor = data['fillColor'] - shapes = ( - ( - s['label'], - s['points'], - s['line_color'], - s['fill_color'], - s.get('shape_type', 'polygon'), - s.get('flags', {}), + shapes = [ + dict( + label=s['label'], + points=s['points'], + line_color=s['line_color'], + fill_color=s['fill_color'], + shape_type=s.get('shape_type', 'polygon'), + flags=s.get('flags', {}), ) for s in data['shapes'] - ) + ] except Exception as e: raise LabelFileError(e) -- GitLab