From c3d1baac5f8d347135efde61327bd3cf0ea91d15 Mon Sep 17 00:00:00 2001 From: "ruifeng.shan" Date: Fri, 21 Apr 2017 15:17:46 +0800 Subject: [PATCH] resolve if don't select default save dir, can't load xml file(saved dir same with image) issue. resolve cannot open annotation xml file issue. --- labelImg.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/labelImg.py b/labelImg.py index 8ce5996a..b125167c 100644 --- a/labelImg.py +++ b/labelImg.py @@ -826,12 +826,16 @@ class MainWindow(QMainWindow, WindowMixin): self.toggleActions(True) # Label xml file and show bound box according to its filename - if self.usingPascalVocFormat is True and \ - self.defaultSaveDir is not None: - basename = os.path.basename( - os.path.splitext(self.filePath)[0]) + XML_EXT - xmlPath = os.path.join(self.defaultSaveDir, basename) - self.loadPascalXMLByFilename(xmlPath) + if self.usingPascalVocFormat is True: + if self.defaultSaveDir is not None: + basename = os.path.basename( + os.path.splitext(self.filePath)[0]) + XML_EXT + xmlPath = os.path.join(self.defaultSaveDir, basename) + self.loadPascalXMLByFilename(xmlPath) + else: + xmlPath = filePath.split(".")[0] + XML_EXT + if os.path.isfile(xmlPath): + self.loadPascalXMLByFilename(xmlPath) self.setWindowTitle(__appname__ + ' ' + filePath) @@ -942,12 +946,12 @@ class MainWindow(QMainWindow, WindowMixin): path = os.path.dirname(u(self.filePath))\ if self.filePath else '.' if self.usingPascalVocFormat: - formats = ['*.%s' % str(fmt).lower() - for fmt in QImageReader.supportedImageFormats()] filters = "Open Annotation XML file (%s)" % \ - ' '.join(formats + ['*.xml']) - filename = str(QFileDialog.getOpenFileName(self, - '%s - Choose a xml file' % __appname__, path, filters)) + ' '.join(['*.xml']) + filename = QFileDialog.getOpenFileName(self,'%s - Choose a xml file' % __appname__, path, filters) + if filename: + if isinstance(filename, (tuple, list)): + filename = filename[0] self.loadPascalXMLByFilename(filename) def openDir(self, _value=False):