diff --git a/labelme/app.py b/labelme/app.py index 31631494d25d6959d4b92e1b04a34e1c729d14e0..01339877056f060c88ae6ecb318f85155b33a3bf 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 abdac5fcbe23c2e8483a530afe55b748645c688c..f7afd7b4781ac35a31f170048c7f1c74b9d484c2 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 470d6f89027a317bdadc91f7287b79398cad99ed..23a78d2c930853b182b0371520566ed912006e27 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 3ddba87cee7876d58fe9355f04c555487cee1276..8847085b1836a8a7d44f8de2d4803d38e17ea7fa 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):