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:
Crystal Silva Campos 2020-09-12 14:49:21 -03:00 committed by GitHub
parent 39b0d68f09
commit 12dadc67cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 24 deletions

View File

@ -210,6 +210,9 @@ class MainWindow(QMainWindow, WindowMixin):
opendir = action(getStr('openDir'), self.openDirDialog, opendir = action(getStr('openDir'), self.openDirDialog,
'Ctrl+u', 'open', getStr('openDir')) 'Ctrl+u', 'open', getStr('openDir'))
copyPrevBounding = action(getStr('copyPrevBounding'), self.copyPreviousBoundingBoxes,
'Ctrl+v', 'paste', getStr('copyPrevBounding'))
changeSavedir = action(getStr('changeSaveDir'), self.changeSavedirDialog, changeSavedir = action(getStr('changeSaveDir'), self.changeSavedirDialog,
'Ctrl+r', 'open', getStr('changeSavedAnnotationDir')) 'Ctrl+r', 'open', getStr('changeSavedAnnotationDir'))
@ -380,7 +383,7 @@ class MainWindow(QMainWindow, WindowMixin):
self.displayLabelOption.triggered.connect(self.togglePaintLabelsOption) self.displayLabelOption.triggered.connect(self.togglePaintLabelsOption)
addActions(self.menus.file, 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.help, (help, showInfo))
addActions(self.menus.view, ( addActions(self.menus.view, (
self.autoSaving, self.autoSaving,
@ -1061,28 +1064,7 @@ class MainWindow(QMainWindow, WindowMixin):
self.paintCanvas() self.paintCanvas()
self.addRecentFile(self.filePath) self.addRecentFile(self.filePath)
self.toggleActions(True) self.toggleActions(True)
self.showXmlBoundingBoxes(filePath)
# 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.setWindowTitle(__appname__ + ' ' + filePath) self.setWindowTitle(__appname__ + ' ' + filePath)
@ -1095,6 +1077,28 @@ class MainWindow(QMainWindow, WindowMixin):
return True return True
return False 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): def resizeEvent(self, event):
if self.canvas and not self.image.isNull()\ if self.canvas and not self.image.isNull()\
and self.zoomMode != self.MANUAL_ZOOM: and self.zoomMode != self.MANUAL_ZOOM:
@ -1494,6 +1498,13 @@ class MainWindow(QMainWindow, WindowMixin):
self.loadLabels(shapes) self.loadLabels(shapes)
self.canvas.verified = tYoloParseReader.verified 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): def togglePaintLabelsOption(self):
for shape in self.canvas.shapes: for shape in self.canvas.shapes:
shape.paintLabel = self.displayLabelOption.isChecked() shape.paintLabel = self.displayLabelOption.isChecked()

View File

@ -31,6 +31,7 @@ save=保存
saveAs=另存为 saveAs=另存为
fitWinDetail=缩放到当前窗口大小 fitWinDetail=缩放到当前窗口大小
openDir=打开目录 openDir=打开目录
copyPrevBounding=复制当前图像中的上一个边界框
showHide=显示/隐藏标签 showHide=显示/隐藏标签
changeSaveFormat=更改存储格式 changeSaveFormat=更改存储格式
shapeFillColor=填充颜色 shapeFillColor=填充颜色

View File

@ -31,6 +31,7 @@ save=儲存
saveAs=另存為 saveAs=另存為
fitWinDetail=縮放到窗口一樣 fitWinDetail=縮放到窗口一樣
openDir=開啟目錄 openDir=開啟目錄
copyPrevBounding=複製當前圖像中的上一個邊界框
showHide=顯示/隱藏標籤 showHide=顯示/隱藏標籤
changeSaveFormat=更改儲存格式 changeSaveFormat=更改儲存格式
shapeFillColor=填充顏色 shapeFillColor=填充顏色

View File

@ -3,6 +3,7 @@ openFileDetail=Open image or label file
quit=Quit quit=Quit
quitApp=Quit application quitApp=Quit application
openDir=Open Dir openDir=Open Dir
copyPrevBounding=Copy previous Bounding Boxes in the current image
changeSavedAnnotationDir=Change default saved Annotation dir changeSavedAnnotationDir=Change default saved Annotation dir
openAnnotation=Open Annotation openAnnotation=Open Annotation
openAnnotationDetail=Open an annotation file openAnnotationDetail=Open an annotation file