Add ctrl+v hotkey to be able copy the bounding boxes from the previous image to the current (#627)
* Add previous bounding boxes code * Create method to avoid repeated code * Fix text in the action copyprevbounding * Add description for different languages
This commit is contained in:
parent
39b0d68f09
commit
12dadc67cd
57
labelImg.py
57
labelImg.py
@ -210,6 +210,9 @@ class MainWindow(QMainWindow, WindowMixin):
|
||||
opendir = action(getStr('openDir'), self.openDirDialog,
|
||||
'Ctrl+u', 'open', getStr('openDir'))
|
||||
|
||||
copyPrevBounding = action(getStr('copyPrevBounding'), self.copyPreviousBoundingBoxes,
|
||||
'Ctrl+v', 'paste', getStr('copyPrevBounding'))
|
||||
|
||||
changeSavedir = action(getStr('changeSaveDir'), self.changeSavedirDialog,
|
||||
'Ctrl+r', 'open', getStr('changeSavedAnnotationDir'))
|
||||
|
||||
@ -380,7 +383,7 @@ class MainWindow(QMainWindow, WindowMixin):
|
||||
self.displayLabelOption.triggered.connect(self.togglePaintLabelsOption)
|
||||
|
||||
addActions(self.menus.file,
|
||||
(open, opendir, changeSavedir, openAnnotation, self.menus.recentFiles, save, save_format, saveAs, close, resetAll, deleteImg, quit))
|
||||
(open, opendir, copyPrevBounding, changeSavedir, openAnnotation, self.menus.recentFiles, save, save_format, saveAs, close, resetAll, deleteImg, quit))
|
||||
addActions(self.menus.help, (help, showInfo))
|
||||
addActions(self.menus.view, (
|
||||
self.autoSaving,
|
||||
@ -1061,28 +1064,7 @@ class MainWindow(QMainWindow, WindowMixin):
|
||||
self.paintCanvas()
|
||||
self.addRecentFile(self.filePath)
|
||||
self.toggleActions(True)
|
||||
|
||||
# Label xml file and show bound box according to its filename
|
||||
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):
|
||||
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.showXmlBoundingBoxes(filePath)
|
||||
|
||||
self.setWindowTitle(__appname__ + ' ' + filePath)
|
||||
|
||||
@ -1095,6 +1077,28 @@ class MainWindow(QMainWindow, WindowMixin):
|
||||
return True
|
||||
return False
|
||||
|
||||
def showXmlBoundingBoxes(self, filePath):
|
||||
if self.defaultSaveDir is not None:
|
||||
basename = os.path.basename(
|
||||
os.path.splitext(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):
|
||||
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)
|
||||
|
||||
def resizeEvent(self, event):
|
||||
if self.canvas and not self.image.isNull()\
|
||||
and self.zoomMode != self.MANUAL_ZOOM:
|
||||
@ -1494,6 +1498,13 @@ class MainWindow(QMainWindow, WindowMixin):
|
||||
self.loadLabels(shapes)
|
||||
self.canvas.verified = tYoloParseReader.verified
|
||||
|
||||
def copyPreviousBoundingBoxes(self):
|
||||
currIndex = self.mImgList.index(self.filePath)
|
||||
prevFilePath = self.mImgList[currIndex - 1]
|
||||
|
||||
self.showXmlBoundingBoxes(prevFilePath)
|
||||
self.saveFile()
|
||||
|
||||
def togglePaintLabelsOption(self):
|
||||
for shape in self.canvas.shapes:
|
||||
shape.paintLabel = self.displayLabelOption.isChecked()
|
||||
|
||||
@ -31,6 +31,7 @@ save=保存
|
||||
saveAs=另存为
|
||||
fitWinDetail=缩放到当前窗口大小
|
||||
openDir=打开目录
|
||||
copyPrevBounding=复制当前图像中的上一个边界框
|
||||
showHide=显示/隐藏标签
|
||||
changeSaveFormat=更改存储格式
|
||||
shapeFillColor=填充颜色
|
||||
|
||||
@ -31,6 +31,7 @@ save=儲存
|
||||
saveAs=另存為
|
||||
fitWinDetail=縮放到窗口一樣
|
||||
openDir=開啟目錄
|
||||
copyPrevBounding=複製當前圖像中的上一個邊界框
|
||||
showHide=顯示/隱藏標籤
|
||||
changeSaveFormat=更改儲存格式
|
||||
shapeFillColor=填充顏色
|
||||
|
||||
@ -3,6 +3,7 @@ openFileDetail=Open image or label file
|
||||
quit=Quit
|
||||
quitApp=Quit application
|
||||
openDir=Open Dir
|
||||
copyPrevBounding=Copy previous Bounding Boxes in the current image
|
||||
changeSavedAnnotationDir=Change default saved Annotation dir
|
||||
openAnnotation=Open Annotation
|
||||
openAnnotationDetail=Open an annotation file
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user