Skip to content

Commit

Permalink
fix the label and changed the color according to label
Browse files Browse the repository at this point in the history
  • Loading branch information
xiecl committed Apr 24, 2019
1 parent 7bef7f8 commit 95af7a0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
*.py[cdo]

.DS_Store
.idea
2 changes: 2 additions & 0 deletions labelme/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,8 @@ def labelItemChanged(self, item):
label = str(item.text())
if label != shape.label:
shape.label = str(item.text())
shape.line_color = self.canvas.labelToColor.get(shape.label, QtGui.QColor(0, 0, 0, 255))
shape.fill_color = self.canvas.labelToColor.get(shape.label, QtGui.QColor(0, 0, 0, 255))
self.setDirty()
else: # User probably changed item visibility
self.canvas.setShapeVisible(shape, item.checkState() == Qt.Checked)
Expand Down
2 changes: 2 additions & 0 deletions labelme/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ def _main():
else:
args.labels = [l for l in args.labels.split(',') if l]

args.labels = ['free_space', 'park_free', 'park_occupy', 'lever', 'corner', 'bucket', 'lock', 'unlock']

config_from_args = args.__dict__
config_from_args.pop('version')
reset_config = config_from_args.pop('reset_config')
Expand Down
12 changes: 12 additions & 0 deletions labelme/widgets/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ def __init__(self, *args, **kwargs):
# Set widget options.
self.setMouseTracking(True)
self.setFocusPolicy(QtCore.Qt.WheelFocus)
self.labelToColor = {
'free_space': QtGui.QColor(0, 128, 128, 128),
'park_free': QtGui.QColor(255, 0, 0, 128),
'park_occupy': QtGui.QColor(255, 0, 255, 128),
'lever': QtGui.QColor(0, 0, 255, 128),
'corner': QtGui.QColor(0, 255, 0, 128),
'bucket': QtGui.QColor(0, 255, 255, 128),
'lock': QtGui.QColor(255, 255, 0, 128),
'unlock': QtGui.QColor(128, 0, 0, 128),
}

def fillDrawing(self):
return self._fill_drawing
Expand Down Expand Up @@ -646,6 +656,8 @@ def keyPressEvent(self, ev):
def setLastLabel(self, text):
assert text
self.shapes[-1].label = text
self.shapes[-1].fill_color = self.labelToColor.get(text, QtGui.QColor(0, 0, 0, 255))
self.shapes[-1].line_color = self.labelToColor.get(text, QtGui.QColor(0, 0, 0, 255))
self.shapesBackups.pop()
self.storeShapes()
return self.shapes[-1]
Expand Down

0 comments on commit 95af7a0

Please sign in to comment.