Skip to content

Commit

Permalink
Add option to enable/disable label painting
Browse files Browse the repository at this point in the history
  • Loading branch information
vdalv authored and tzutalin committed May 19, 2018
1 parent 219e50d commit e7a7b64
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
13 changes: 12 additions & 1 deletion labelImg.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,13 +370,20 @@ def __init__(self, defaultFilename=None, defaultPrefdefClassFile=None, defaultSa
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))
addActions(self.menus.help, (help, showInfo))
addActions(self.menus.view, (
self.autoSaving,
self.singleClassMode,
self.paintLabelsOption,
labels, advancedMode, None,
hideAll, showAll, None,
zoomIn, zoomOut, zoomOrg, None,
Expand Down Expand Up @@ -709,6 +716,7 @@ def shapeSelectionChanged(self, selected=False):
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)
Expand Down Expand Up @@ -1399,7 +1407,10 @@ def loadYOLOTXTByFilename(self, txtPath):
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()])
Expand Down
30 changes: 16 additions & 14 deletions libs/shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -110,19 +111,20 @@ def paint(self, painter):
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
Expand Down

0 comments on commit e7a7b64

Please sign in to comment.