Skip to content

Commit e7a7b64

Browse files
vdalvtzutalin
authored andcommitted
Add option to enable/disable label painting
1 parent 219e50d commit e7a7b64

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

labelImg.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,13 +370,20 @@ def __init__(self, defaultFilename=None, defaultPrefdefClassFile=None, defaultSa
370370
self.singleClassMode.setCheckable(True)
371371
self.singleClassMode.setChecked(settings.get(SETTING_SINGLE_CLASS, False))
372372
self.lastLabel = None
373+
# Add option to enable/disable labels being painted at the top of bounding boxes
374+
self.paintLabelsOption = QAction("Paint Labels", self)
375+
self.paintLabelsOption.setShortcut("Ctrl+Shift+P")
376+
self.paintLabelsOption.setCheckable(True)
377+
self.paintLabelsOption.setChecked(False)
378+
self.paintLabelsOption.triggered.connect(self.togglePaintLabelsOption)
373379

374380
addActions(self.menus.file,
375381
(open, opendir, changeSavedir, openAnnotation, self.menus.recentFiles, save, save_format, saveAs, close, resetAll, quit))
376382
addActions(self.menus.help, (help, showInfo))
377383
addActions(self.menus.view, (
378384
self.autoSaving,
379385
self.singleClassMode,
386+
self.paintLabelsOption,
380387
labels, advancedMode, None,
381388
hideAll, showAll, None,
382389
zoomIn, zoomOut, zoomOrg, None,
@@ -709,6 +716,7 @@ def shapeSelectionChanged(self, selected=False):
709716
self.actions.shapeFillColor.setEnabled(selected)
710717

711718
def addLabel(self, shape):
719+
shape.paintLabel = self.paintLabelsOption.isChecked()
712720
item = HashableQListWidgetItem(shape.label)
713721
item.setFlags(item.flags() | Qt.ItemIsUserCheckable)
714722
item.setCheckState(Qt.Checked)
@@ -1399,7 +1407,10 @@ def loadYOLOTXTByFilename(self, txtPath):
13991407
self.loadLabels(shapes)
14001408
self.canvas.verified = tYoloParseReader.verified
14011409

1402-
1410+
def togglePaintLabelsOption(self):
1411+
paintLabelsOptionChecked = self.paintLabelsOption.isChecked()
1412+
for shape in self.canvas.shapes:
1413+
shape.paintLabel = paintLabelsOptionChecked
14031414

14041415
def inverted(color):
14051416
return QColor(*[255 - v for v in color.getRgb()])

libs/shape.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@ class Shape(object):
3737
point_size = 8
3838
scale = 1.0
3939

40-
def __init__(self, label=None, line_color=None,difficult = False):
40+
def __init__(self, label=None, line_color=None, difficult=False, paintLabel=False):
4141
self.label = label
4242
self.points = []
4343
self.fill = False
4444
self.selected = False
4545
self.difficult = difficult
46+
self.paintLabel = paintLabel
4647

4748
self._highlightIndex = None
4849
self._highlightMode = self.NEAR_VERTEX
@@ -110,19 +111,20 @@ def paint(self, painter):
110111
painter.fillPath(vrtx_path, self.vertex_fill_color)
111112

112113
# Draw text at the top-left
113-
min_x = sys.maxsize
114-
min_y = sys.maxsize
115-
for point in self.points:
116-
min_x = min(min_x, point.x())
117-
min_y = min(min_y, point.y())
118-
if min_x != sys.maxsize and min_y != sys.maxsize:
119-
font = QFont()
120-
font.setPointSize(8)
121-
font.setBold(True)
122-
painter.setFont(font)
123-
if(self.label == None):
124-
self.label = ""
125-
painter.drawText(min_x, min_y, self.label)
114+
if self.paintLabel:
115+
min_x = sys.maxsize
116+
min_y = sys.maxsize
117+
for point in self.points:
118+
min_x = min(min_x, point.x())
119+
min_y = min(min_y, point.y())
120+
if min_x != sys.maxsize and min_y != sys.maxsize:
121+
font = QFont()
122+
font.setPointSize(8)
123+
font.setBold(True)
124+
painter.setFont(font)
125+
if(self.label == None):
126+
self.label = ""
127+
painter.drawText(min_x, min_y, self.label)
126128

127129
if self.fill:
128130
color = self.select_fill_color if self.selected else self.fill_color

0 commit comments

Comments
 (0)