diff --git a/labelme/app.py b/labelme/app.py index 84c37ec4a..76780542c 100644 --- a/labelme/app.py +++ b/labelme/app.py @@ -82,6 +82,7 @@ def __init__( Shape.vertex_fill_color = QtGui.QColor( *self._config["shape"]["vertex_fill_color"] ) + Shape.show_labels = self._config["shape"]["show_labels"] Shape.hvertex_fill_color = QtGui.QColor( *self._config["shape"]["hvertex_fill_color"] ) diff --git a/labelme/config/default_config.yaml b/labelme/config/default_config.yaml index 260066f65..18b3509e7 100644 --- a/labelme/config/default_config.yaml +++ b/labelme/config/default_config.yaml @@ -24,6 +24,7 @@ shape: line_color: [0, 255, 0, 128] fill_color: [0, 255, 0, 0] # transparent vertex_fill_color: [0, 255, 0, 255] + show_labels: false # selecting / hovering select_line_color: [255, 255, 255, 255] select_fill_color: [0, 255, 0, 155] diff --git a/labelme/shape.py b/labelme/shape.py index 86e7f2598..425954ce9 100644 --- a/labelme/shape.py +++ b/labelme/shape.py @@ -17,6 +17,7 @@ DEFAULT_SELECT_FILL_COLOR = QtGui.QColor(0, 255, 0, 155) # selected DEFAULT_VERTEX_FILL_COLOR = QtGui.QColor(0, 255, 0, 255) # hovering DEFAULT_HVERTEX_FILL_COLOR = QtGui.QColor(255, 255, 255, 255) # hovering +DEFAULT_SHOW_LABELS = False class Shape(object): @@ -32,6 +33,7 @@ class Shape(object): select_fill_color = DEFAULT_SELECT_FILL_COLOR vertex_fill_color = DEFAULT_VERTEX_FILL_COLOR hvertex_fill_color = DEFAULT_HVERTEX_FILL_COLOR + show_labels = DEFAULT_SHOW_LABELS point_type = P_ROUND point_size = 8 scale = 1.0 @@ -168,6 +170,16 @@ def paint(self, painter): if self.isClosed(): line_path.lineTo(self.points[0]) + if self.show_labels: + painter.setFont(QtGui.QFont("Arial", 25)) + label_x, label_y = self.points[0].x(), self.points[0].y() + for p in self.points: + if p.x() < label_x: + label_x = p.x() + label_y = p.y() + shift_y = 20 * (2 if len(self.label) > 2 else 1) + painter.drawText(label_x - 15, label_y - shift_y, self.label) + painter.drawPath(line_path) painter.drawPath(vrtx_path) painter.fillPath(vrtx_path, self._vertex_fill_color)