赞
踩
labelimg是目标检测领域最常使用的标注工具之一,工具地址https://github.com/tzutalin/labelImg 。
1、按照自己的想法修改ui风格
1.1默认ui风格如下
默认的ui风格我认为存在两个问题
1:在edit label的状态下(是小手图标,可以通过拖拽方式修改坐标信息),fill_color的颜色过深,可能会影响细节信息的判断
2: display label显示的标签太小,不显眼。
1.2 修改源码,按照自己的想法修改ui
1.2.1 修改填充的颜色
修改文件libs/shape.py文件
1.2.2 修改display label字体大小
修改文件libs/shape.py文件
2、修改快捷键
为了更快检查标记结果,可以重新设置相关快捷键
2.1直接使用快捷键修改label的类别,省去鼠标多次双击操作
修改labelImg.py文件
edit = action(getStr(‘editLabel’), self.editLabel,
‘Ctrl+E’, ‘edit’, getStr(‘editLabelDetail’),
enabled=False)
#仿照edit label操作,并添加相关代码
edit1 = action(getStr('editLabel'), self.editLabel1, '1', 'edit', getStr('editLabelDetail'), #快捷键可以自己定义,我是定义的‘1’ enabled=False) edit2 = action(getStr('editLabel'), self.editLabel2, '2', 'edit', getStr('editLabelDetail'), enabled=False) self.editButton.setDefaultAction(edit) self.editButton.setDefaultAction(edit1) self.editButton.setDefaultAction(edit2) addActions(labelMenu, (edit, delete)) addActions(labelMenu, (edit1, delete)) addActions(labelMenu, (edit2, delete)) self.actions = struct(save=save, save_format=save_format, saveAs=saveAs, open=open, close=close, resetAll = resetAll, lineColor=color1, create=create, delete=delete, edit=edit, edit1=edit1,edit2=edit2,copy=copy, createMode=createMode, editMode=editMode, advancedMode=advancedMode, shapeLineColor=shapeLineColor, shapeFillColor=shapeFillColor, zoom=zoom, zoomIn=zoomIn, zoomOut=zoomOut, zoomOrg=zoomOrg, fitWindow=fitWindow, fitWidth=fitWidth, zoomActions=zoomActions, fileMenuActions=( open, opendir, save, saveAs, close, resetAll, quit), beginner=(), advanced=(), editMenu=(edit,edit1,edit2, copy, delete, None, color1, self.drawSquaresOption), beginnerContext=(create, edit,edit1,edit2, copy, delete), advancedContext=(createMode, editMode, edit,edit1,edit2, copy, delete, shapeLineColor, shapeFillColor), onLoadActive=( close, create, createMode, editMode), onShapesPresent=(saveAs, hideAll, showAll)) def editLabel(self): if not self.canvas.editing(): return item = self.currentItem() text = self.labelDialog.popUp(item.text()) if text is not None: item.setText(text) item.setBackground(generateColorByText(text)) self.setDirty() def editLabel1(self): if not self.canvas.editing(): return item = self.currentItem() if not item: return if len(self.labelHist) >= 1: text = self.labelHist[0] #根据class.txt,获取标签。此处获取class中的第一个标签 if text is not None: item.setText(text) item.setBackground(generateColorByText(text)) self.setDirty() def editLabel2(self): if not self.canvas.editing(): return item = self.currentItem() if not item: return if len(self.labelHist) >= 1: text = self.labelHist[1] #获取第二个标签 if text is not None: item.setText(text) item.setBackground(generateColorByText(text)) self.setDirty() self.actions.edit.setEnabled(selected) self.actions.edit1.setEnabled(selected) self.actions.edit2.setEnabled(selected)
通过仿照edit操作,添加自己想要的快捷操作。上述的粉色部分就是添加了两个快捷操作。分别使用键盘上的1,2两个键直接修改框的标签类别,可以大大加快审核速度。
3、
在数据清洗过程中,点击下一张图不希望回显矩形框,希望点击一个标签则回显一个标签。
def loadFile(self, filePath=None):
“”“Load the specified file, or the last opened file if None.”“”
self.resetState()
self.canvas.setEnabled(False)
if filePath is None:
filePath = self.settings.get(SETTING_FILENAME)
# Make sure that filePath is a regular python string, rather than QString filePath = ustr(filePath) unicodeFilePath = ustr(filePath) # Tzutalin 20160906 : Add file list and dock to move faster # Highlight the file item if unicodeFilePath and self.fileListWidget.count() > 0: index = self.mImgList.index(unicodeFilePath) fileWidgetItem = self.fileListWidget.item(index) fileWidgetItem.setSelected(True) if unicodeFilePath and os.path.exists(unicodeFilePath): if LabelFile.isLabelFile(unicodeFilePath): try: self.labelFile = LabelFile(unicodeFilePath) except LabelFileError as e: self.errorMessage(u'Error opening file', (u"<p><b>%s</b></p>" u"<p>Make sure <i>%s</i> is a valid label file.") % (e, unicodeFilePath)) self.status("Error reading %s" % unicodeFilePath) return False self.imageData = self.labelFile.imageData self.lineColor = QColor(*self.labelFile.lineColor) self.fillColor = QColor(*self.labelFile.fillColor) self.canvas.verified = self.labelFile.verified else: # Load image: # read data first and store for saving into label file. self.imageData = read(unicodeFilePath, None) self.labelFile = None self.canvas.verified = False image = QImage.fromData(self.imageData) if image.isNull(): self.errorMessage(u'Error opening file', u"<p>Make sure <i>%s</i> is a valid image file." % unicodeFilePath) self.status("Error reading %s" % unicodeFilePath) return False self.status("Loaded %s" % os.path.basename(unicodeFilePath)) self.image = image self.filePath = unicodeFilePath self.canvas.loadPixmap(QPixmap.fromImage(image)) if self.labelFile: self.loadLabels(self.labelFile.shapes) self.setClean() self.canvas.setEnabled(True) # self.canvas.setEnabled(False) self.adjustScale(initial=True) self.paintCanvas() self.addRecentFile(self.filePath) self.toggleActions(True) # Label xml file and show bound box according to its filename # if self.usingPascalVocFormat is True: if self.defaultSaveDir is not None: basename = os.path.basename( os.path.splitext(self.filePath)[0]) xmlPath = os.path.join(self.defaultSaveDir, basename + XML_EXT) txtPath = os.path.join(self.defaultSaveDir, basename + TXT_EXT) """Annotation file priority: PascalXML > YOLO """ if os.path.isfile(xmlPath): # pass self.loadPascalXMLByFilename(xmlPath) elif os.path.isfile(txtPath): self.loadYOLOTXTByFilename(txtPath) else: xmlPath = os.path.splitext(filePath)[0] + XML_EXT txtPath = os.path.splitext(filePath)[0] + TXT_EXT if os.path.isfile(xmlPath): self.loadPascalXMLByFilename(xmlPath) elif os.path.isfile(txtPath): self.loadYOLOTXTByFilename(txtPath) self.setWindowTitle(__appname__ + ' ' + filePath) # Default : select last item if there is at least one item if self.labelList.count(): self.labelList.setCurrentItem(self.labelList.item(self.labelList.count()-1)) self.labelList.item(self.labelList.count()-1).setSelected(True) self.canvas.setFocus(True) ##### 添加下面这行代码。相当如标签载入后点击ctrl h(hide rectangel),隐藏矩形框 self.togglePolygons(False) return True return False
3编辑鼠标快捷键
我使用的罗技鼠标是可编辑的,我编辑了侧面的两个按键,分别代表1,2。这样可以直接修改框的位置,并使用鼠标快捷键修改类别。
4编译labelimg.py生成labelimg.exe文件
为了去掉环境等依赖,可以生成exe文件,把文件打包给实习生(实习生电脑没环境python,pyqt等)使用。
pip install pyinstaller
pyinstaller -F labelImg.py -p D:\软件包\labelImg-master_revisedbylrr
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。