Ver código fonte

Annotate label from list

Kentaro Wada 7 anos atrás
pai
commit
bc7e0ac698
2 arquivos alterados com 26 adições e 4 exclusões
  1. 9 3
      labelme/app.py
  2. 17 1
      labelme/labelDialog.py

+ 9 - 3
labelme/app.py

@@ -90,7 +90,8 @@ class WindowMixin(object):
 class MainWindow(QMainWindow, WindowMixin):
     FIT_WINDOW, FIT_WIDTH, MANUAL_ZOOM = 0, 1, 2
 
-    def __init__(self, filename=None, output=None, store_data=True):
+    def __init__(self, filename=None, output=None, store_data=True,
+                 labels=None):
         super(MainWindow, self).__init__()
         self.setWindowTitle(__appname__)
 
@@ -103,7 +104,7 @@ class MainWindow(QMainWindow, WindowMixin):
         self.screencast = "screencast.ogv"
 
         # Main widgets and related state.
-        self.labelDialog = LabelDialog(parent=self)
+        self.labelDialog = LabelDialog(parent=self, labels=labels)
 
         self.labelList = QListWidget()
         self.itemsToShapes = []
@@ -610,6 +611,7 @@ class MainWindow(QMainWindow, WindowMixin):
         text = self.labelDialog.popUp()
         if text is not None:
             self.addLabel(self.canvas.setLastLabel(text))
+            self.labelDialog.addLabelHistory(text)
             if self.beginner(): # Switch to edit mode.
                 self.canvas.setEditing(True)
                 self.actions.create.setEnabled(True)
@@ -962,12 +964,16 @@ def main():
     parser.add_argument('--output', '-O', '-o', help='output label name')
     parser.add_argument('--nodata', dest='store_data', action='store_false',
                         help='Stop storing image data to JSON file.')
+    parser.add_argument('--labels', help='Camma separated list of labels')
     args = parser.parse_args()
 
+    if args.labels is not None:
+        args.labels = args.labels.split(',')
+
     app = QApplication(sys.argv)
     app.setApplicationName(__appname__)
     app.setWindowIcon(newIcon("app"))
-    win = MainWindow(args.filename, args.output, args.store_data)
+    win = MainWindow(args.filename, args.output, args.store_data, args.labels)
     win.show()
     win.raise_()
     sys.exit(app.exec_())

+ 17 - 1
labelme/labelDialog.py

@@ -36,7 +36,7 @@ BB = QDialogButtonBox
 
 class LabelDialog(QDialog):
 
-    def __init__(self, text="Enter object label", parent=None):
+    def __init__(self, text="Enter object label", parent=None, labels=None):
         super(LabelDialog, self).__init__(parent)
         self.edit = QLineEdit()
         self.edit.setPlaceholderText(text)
@@ -44,14 +44,30 @@ class LabelDialog(QDialog):
         self.edit.editingFinished.connect(self.postProcess)
         layout = QVBoxLayout()
         layout.addWidget(self.edit)
+        # buttons
         self.buttonBox = bb = BB(BB.Ok | BB.Cancel, Qt.Horizontal, self)
         bb.button(BB.Ok).setIcon(newIcon('done'))
         bb.button(BB.Cancel).setIcon(newIcon('undo'))
         bb.accepted.connect(self.validate)
         bb.rejected.connect(self.reject)
         layout.addWidget(bb)
+        # label_list
+        self.labelList = QListWidget()
+        if labels:
+            self.labelList.addItems(labels)
+        self.labelList.currentItemChanged.connect(self.labelSelected)
+        layout.addWidget(self.labelList)
         self.setLayout(layout)
 
+    def addLabelHistory(self, label):
+        if self.labelList.findItems(label, Qt.MatchExactly):
+            return
+        self.labelList.addItem(label)
+        self.labelList.sortItems()
+
+    def labelSelected(self, item):
+        self.edit.setText(item.text())
+
     def validate(self):
         if PYQT5:
             if self.edit.text().strip():