Explorar el Código

Use shapes as list of dictionary

Kentaro Wada hace 5 años
padre
commit
34c88be4cd
Se han modificado 2 ficheros con 18 adiciones y 11 borrados
  1. 8 1
      labelme/app.py
  2. 10 10
      labelme/label_file.py

+ 8 - 1
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))

+ 10 - 10
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)