Explorar o código

Add shape_color, label_colors config

```
labelme data_annotated --labels labels.txt --config
  '{shape_color: manual, label_colors: {person: [0, 0, 255]}, default_shape_color: [255,0,0]}'
```
Kentaro Wada %!s(int64=5) %!d(string=hai) anos
pai
achega
862e0b04df
Modificáronse 4 ficheiros con 27 adicións e 8 borrados
  1. 11 2
      labelme/app.py
  2. 5 0
      labelme/config/__init__.py
  3. 4 0
      labelme/config/default_config.yaml
  4. 7 6
      labelme/shape.py

+ 11 - 2
labelme/app.py

@@ -974,11 +974,20 @@ class MainWindow(QtWidgets.QMainWindow):
         for action in self.actions.onShapesPresent:
             action.setEnabled(True)
 
-        r, g, b = self._get_rgb_by_label(shape.label)
+        if self._config['shape_color'] == 'auto':
+            r, g, b = self._get_rgb_by_label(shape.label)
+        elif (self._config['shape_color'] == 'manual' and
+              self._config['label_colors'] and
+              shape.label in self._config['label_colors']):
+            r, g, b = self._config['label_colors'][shape.label]
+        elif self._config['default_shape_color']:
+            r, g, b = self._config['default_shape_color']
+        else:
+            return
         shape.line_color = QtGui.QColor(r, g, b)
         shape.vertex_fill_color = QtGui.QColor(r, g, b)
         shape.hvertex_fill_color = QtGui.QColor(255, 255, 255)
-        shape.fill_color = QtGui.QColor(r, g, b, 127)
+        shape.fill_color = QtGui.QColor(r, g, b, 128)
         shape.select_line_color = QtGui.QColor(255, 255, 255)
         shape.select_fill_color = QtGui.QColor(r, g, b, 155)
 

+ 5 - 0
labelme/config/__init__.py

@@ -49,6 +49,11 @@ def validate_config_item(key, value):
             "Unexpected value for config key 'validate_label': {}"
             .format(value)
         )
+    if key == 'shape_color' and value not in [None, 'auto', 'manual']:
+        raise ValueError(
+            "Unexpected value for config key 'shape_color': {}"
+            .format(value)
+        )
     if key == 'labels' and value is not None and len(value) != len(set(value)):
         raise ValueError(
             "Duplicates are detected for config key 'labels': {}".format(value)

+ 4 - 0
labelme/config/default_config.yaml

@@ -13,6 +13,10 @@ file_search: null
 sort_labels: true
 validate_label: null
 
+default_shape_color: null
+shape_color: auto   # null, 'auto', 'manual'
+label_colors: null
+
 # main
 flag_dock:
   show: true

+ 7 - 6
labelme/shape.py

@@ -11,12 +11,13 @@ import labelme.utils
 # - [opt] Store paths instead of creating new ones at each paint.
 
 
-DEFAULT_LINE_COLOR = QtGui.QColor(0, 255, 0, 128)           # before hovering
-DEFAULT_FILL_COLOR = QtGui.QColor(255, 0, 0, 128)           # hovering
-DEFAULT_SELECT_LINE_COLOR = QtGui.QColor(255, 255, 255)     # selected
-DEFAULT_SELECT_FILL_COLOR = QtGui.QColor(0, 128, 255, 155)  # selected
-DEFAULT_VERTEX_FILL_COLOR = QtGui.QColor(0, 255, 0, 255)    # hovering
-DEFAULT_HVERTEX_FILL_COLOR = QtGui.QColor(255, 0, 0, 255)   # hovering
+R, G, B = SHAPE_COLOR = 0, 255, 0  # green
+DEFAULT_LINE_COLOR = QtGui.QColor(R, G, B, 128)                # bf hovering
+DEFAULT_FILL_COLOR = QtGui.QColor(R, G, B, 128)                # hovering
+DEFAULT_SELECT_LINE_COLOR = QtGui.QColor(255, 255, 255)        # selected
+DEFAULT_SELECT_FILL_COLOR = QtGui.QColor(R, G, B, 155)         # selected
+DEFAULT_VERTEX_FILL_COLOR = QtGui.QColor(R, G, B, 255)         # hovering
+DEFAULT_HVERTEX_FILL_COLOR = QtGui.QColor(255, 255, 255, 255)  # hovering
 
 
 class Shape(object):