From 862e0b04dfee4aafa7a8447bb0f2455299fa5882 Mon Sep 17 00:00:00 2001 From: Kentaro Wada Date: Sun, 26 Jan 2020 07:38:43 +0000 Subject: [PATCH] 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]}' ``` --- labelme/app.py | 13 +++++++++++-- labelme/config/__init__.py | 5 +++++ labelme/config/default_config.yaml | 4 ++++ labelme/shape.py | 13 +++++++------ 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/labelme/app.py b/labelme/app.py index 3163149..0133987 100644 --- a/labelme/app.py +++ b/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) diff --git a/labelme/config/__init__.py b/labelme/config/__init__.py index abdac5f..f7afd7b 100644 --- a/labelme/config/__init__.py +++ b/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) diff --git a/labelme/config/default_config.yaml b/labelme/config/default_config.yaml index 470d6f8..23a78d2 100644 --- a/labelme/config/default_config.yaml +++ b/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 diff --git a/labelme/shape.py b/labelme/shape.py index 3ddba87..8847085 100644 --- a/labelme/shape.py +++ b/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): -- GitLab