From 6db1dd500d83e8367eaec045120dd7cd29bb9c3d Mon Sep 17 00:00:00 2001 From: tzutalin Date: Sun, 2 Dec 2018 20:25:16 -0800 Subject: [PATCH] FIx issue#403 --- README.rst | 2 +- labelImg.py | 16 +++++++++------- tests/{test.bmp => test.512.512.bmp} | Bin tests/test_io.py | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) rename tests/{test.bmp => test.512.512.bmp} (100%) diff --git a/README.rst b/README.rst index f32b0b3b..7cc9f1dc 100644 --- a/README.rst +++ b/README.rst @@ -28,7 +28,7 @@ Installation Download prebuilt binaries ~~~~~~~~~~~~~~~~~~~~~~~~~~ -- `Windows & Linux `__ +- `Windows `__ - macOS. Binaries for macOS are not yet available. Help would be appreciated. At present, it must be `built from source <#macos>`__. diff --git a/labelImg.py b/labelImg.py index 1c8f5547..ece1d031 100755 --- a/labelImg.py +++ b/labelImg.py @@ -795,20 +795,19 @@ class MainWindow(QMainWindow, WindowMixin): # Can add differrent annotation formats here try: if self.usingPascalVocFormat is True: - if ustr(annotationFilePath[-4:]) != ".xml": + if annotationFilePath[-4:].lower() != ".xml": annotationFilePath += XML_EXT - print ('Img: ' + self.filePath + ' -> Its xml: ' + annotationFilePath) self.labelFile.savePascalVocFormat(annotationFilePath, shapes, self.filePath, self.imageData, self.lineColor.getRgb(), self.fillColor.getRgb()) elif self.usingYoloFormat is True: - if annotationFilePath[-4:] != ".txt": + if annotationFilePath[-4:].lower() != ".txt": annotationFilePath += TXT_EXT - print ('Img: ' + self.filePath + ' -> Its txt: ' + annotationFilePath) self.labelFile.saveYoloFormat(annotationFilePath, shapes, self.filePath, self.imageData, self.labelHist, self.lineColor.getRgb(), self.fillColor.getRgb()) else: self.labelFile.save(annotationFilePath, shapes, self.filePath, self.imageData, self.lineColor.getRgb(), self.fillColor.getRgb()) + print('Image:{0} -> Annotation:{1}'.format(self.filePath, annotationFilePath)) return True except LabelFileError as e: self.errorMessage(u'Error saving label data', u'%s' % e) @@ -1293,13 +1292,13 @@ class MainWindow(QMainWindow, WindowMixin): savedFileName = os.path.splitext(imgFileName)[0] savedPath = os.path.join(imgFileDir, savedFileName) self._saveFile(savedPath if self.labelFile - else self.saveFileDialog()) + else self.saveFileDialog(removeExt=False)) def saveFileAs(self, _value=False): assert not self.image.isNull(), "cannot save empty image" self._saveFile(self.saveFileDialog()) - def saveFileDialog(self): + def saveFileDialog(self, removeExt=True): caption = '%s - Choose File' % __appname__ filters = 'File (*%s)' % LabelFile.suffix openDialogPath = self.currentPath() @@ -1311,7 +1310,10 @@ class MainWindow(QMainWindow, WindowMixin): dlg.setOption(QFileDialog.DontUseNativeDialog, False) if dlg.exec_(): fullFilePath = ustr(dlg.selectedFiles()[0]) - return os.path.splitext(fullFilePath)[0] # Return file path without the extension. + if removeExt: + return os.path.splitext(fullFilePath)[0] # Return file path without the extension. + else: + return fullFilePath return '' def _saveFile(self, annotationFilePath): diff --git a/tests/test.bmp b/tests/test.512.512.bmp similarity index 100% rename from tests/test.bmp rename to tests/test.512.512.bmp diff --git a/tests/test_io.py b/tests/test_io.py index bfdb8a08..7067b403 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -12,7 +12,7 @@ class TestPascalVocRW(unittest.TestCase): from pascal_voc_io import PascalVocReader # Test Write/Read - writer = PascalVocWriter('tests', 'test', (512, 512, 1), localImgPath='tests/test.bmp') + writer = PascalVocWriter('tests', 'test', (512, 512, 1), localImgPath='tests/test.512.512.bmp') difficult = 1 writer.addBndBox(60, 40, 430, 504, 'person', difficult) writer.addBndBox(113, 40, 450, 403, 'face', difficult)