From e7a7b64f7ec40fd60e71ce9d62bb005cc5d898b7 Mon Sep 17 00:00:00 2001 From: vdalv Date: Thu, 17 May 2018 22:57:47 -0700 Subject: [PATCH] Add option to enable/disable label painting --- labelImg.py | 13 ++++++++++++- libs/shape.py | 30 ++++++++++++++++-------------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/labelImg.py b/labelImg.py index 6290f188..19c52a77 100755 --- a/labelImg.py +++ b/labelImg.py @@ -370,6 +370,12 @@ class MainWindow(QMainWindow, WindowMixin): self.singleClassMode.setCheckable(True) self.singleClassMode.setChecked(settings.get(SETTING_SINGLE_CLASS, False)) self.lastLabel = None + # Add option to enable/disable labels being painted at the top of bounding boxes + self.paintLabelsOption = QAction("Paint Labels", self) + self.paintLabelsOption.setShortcut("Ctrl+Shift+P") + self.paintLabelsOption.setCheckable(True) + self.paintLabelsOption.setChecked(False) + self.paintLabelsOption.triggered.connect(self.togglePaintLabelsOption) addActions(self.menus.file, (open, opendir, changeSavedir, openAnnotation, self.menus.recentFiles, save, save_format, saveAs, close, resetAll, quit)) @@ -377,6 +383,7 @@ class MainWindow(QMainWindow, WindowMixin): addActions(self.menus.view, ( self.autoSaving, self.singleClassMode, + self.paintLabelsOption, labels, advancedMode, None, hideAll, showAll, None, zoomIn, zoomOut, zoomOrg, None, @@ -709,6 +716,7 @@ class MainWindow(QMainWindow, WindowMixin): self.actions.shapeFillColor.setEnabled(selected) def addLabel(self, shape): + shape.paintLabel = self.paintLabelsOption.isChecked() item = HashableQListWidgetItem(shape.label) item.setFlags(item.flags() | Qt.ItemIsUserCheckable) item.setCheckState(Qt.Checked) @@ -1399,7 +1407,10 @@ class MainWindow(QMainWindow, WindowMixin): self.loadLabels(shapes) self.canvas.verified = tYoloParseReader.verified - + def togglePaintLabelsOption(self): + paintLabelsOptionChecked = self.paintLabelsOption.isChecked() + for shape in self.canvas.shapes: + shape.paintLabel = paintLabelsOptionChecked def inverted(color): return QColor(*[255 - v for v in color.getRgb()]) diff --git a/libs/shape.py b/libs/shape.py index 27469bc8..e8dafb38 100644 --- a/libs/shape.py +++ b/libs/shape.py @@ -37,12 +37,13 @@ class Shape(object): point_size = 8 scale = 1.0 - def __init__(self, label=None, line_color=None,difficult = False): + def __init__(self, label=None, line_color=None, difficult=False, paintLabel=False): self.label = label self.points = [] self.fill = False self.selected = False self.difficult = difficult + self.paintLabel = paintLabel self._highlightIndex = None self._highlightMode = self.NEAR_VERTEX @@ -110,19 +111,20 @@ class Shape(object): painter.fillPath(vrtx_path, self.vertex_fill_color) # Draw text at the top-left - min_x = sys.maxsize - min_y = sys.maxsize - for point in self.points: - min_x = min(min_x, point.x()) - min_y = min(min_y, point.y()) - if min_x != sys.maxsize and min_y != sys.maxsize: - font = QFont() - font.setPointSize(8) - font.setBold(True) - painter.setFont(font) - if(self.label == None): - self.label = "" - painter.drawText(min_x, min_y, self.label) + if self.paintLabel: + min_x = sys.maxsize + min_y = sys.maxsize + for point in self.points: + min_x = min(min_x, point.x()) + min_y = min(min_y, point.y()) + if min_x != sys.maxsize and min_y != sys.maxsize: + font = QFont() + font.setPointSize(8) + font.setBold(True) + painter.setFont(font) + if(self.label == None): + self.label = "" + painter.drawText(min_x, min_y, self.label) if self.fill: color = self.select_fill_color if self.selected else self.fill_color