FIx issue#403

This commit is contained in:
tzutalin 2018-12-02 20:25:16 -08:00
parent eaac031404
commit 6db1dd500d
4 changed files with 11 additions and 9 deletions

View File

@ -28,7 +28,7 @@ Installation
Download prebuilt binaries Download prebuilt binaries
~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~
- `Windows & Linux <https://tzutalin.github.io/labelImg/>`__ - `Windows <https://github.com/tzutalin/labelImg/releases>`__
- macOS. Binaries for macOS are not yet available. Help would be appreciated. At present, it must be `built from source <#macos>`__. - macOS. Binaries for macOS are not yet available. Help would be appreciated. At present, it must be `built from source <#macos>`__.

View File

@ -795,20 +795,19 @@ class MainWindow(QMainWindow, WindowMixin):
# Can add differrent annotation formats here # Can add differrent annotation formats here
try: try:
if self.usingPascalVocFormat is True: if self.usingPascalVocFormat is True:
if ustr(annotationFilePath[-4:]) != ".xml": if annotationFilePath[-4:].lower() != ".xml":
annotationFilePath += XML_EXT annotationFilePath += XML_EXT
print ('Img: ' + self.filePath + ' -> Its xml: ' + annotationFilePath)
self.labelFile.savePascalVocFormat(annotationFilePath, shapes, self.filePath, self.imageData, self.labelFile.savePascalVocFormat(annotationFilePath, shapes, self.filePath, self.imageData,
self.lineColor.getRgb(), self.fillColor.getRgb()) self.lineColor.getRgb(), self.fillColor.getRgb())
elif self.usingYoloFormat is True: elif self.usingYoloFormat is True:
if annotationFilePath[-4:] != ".txt": if annotationFilePath[-4:].lower() != ".txt":
annotationFilePath += TXT_EXT annotationFilePath += TXT_EXT
print ('Img: ' + self.filePath + ' -> Its txt: ' + annotationFilePath)
self.labelFile.saveYoloFormat(annotationFilePath, shapes, self.filePath, self.imageData, self.labelHist, self.labelFile.saveYoloFormat(annotationFilePath, shapes, self.filePath, self.imageData, self.labelHist,
self.lineColor.getRgb(), self.fillColor.getRgb()) self.lineColor.getRgb(), self.fillColor.getRgb())
else: else:
self.labelFile.save(annotationFilePath, shapes, self.filePath, self.imageData, self.labelFile.save(annotationFilePath, shapes, self.filePath, self.imageData,
self.lineColor.getRgb(), self.fillColor.getRgb()) self.lineColor.getRgb(), self.fillColor.getRgb())
print('Image:{0} -> Annotation:{1}'.format(self.filePath, annotationFilePath))
return True return True
except LabelFileError as e: except LabelFileError as e:
self.errorMessage(u'Error saving label data', u'<b>%s</b>' % e) self.errorMessage(u'Error saving label data', u'<b>%s</b>' % e)
@ -1293,13 +1292,13 @@ class MainWindow(QMainWindow, WindowMixin):
savedFileName = os.path.splitext(imgFileName)[0] savedFileName = os.path.splitext(imgFileName)[0]
savedPath = os.path.join(imgFileDir, savedFileName) savedPath = os.path.join(imgFileDir, savedFileName)
self._saveFile(savedPath if self.labelFile self._saveFile(savedPath if self.labelFile
else self.saveFileDialog()) else self.saveFileDialog(removeExt=False))
def saveFileAs(self, _value=False): def saveFileAs(self, _value=False):
assert not self.image.isNull(), "cannot save empty image" assert not self.image.isNull(), "cannot save empty image"
self._saveFile(self.saveFileDialog()) self._saveFile(self.saveFileDialog())
def saveFileDialog(self): def saveFileDialog(self, removeExt=True):
caption = '%s - Choose File' % __appname__ caption = '%s - Choose File' % __appname__
filters = 'File (*%s)' % LabelFile.suffix filters = 'File (*%s)' % LabelFile.suffix
openDialogPath = self.currentPath() openDialogPath = self.currentPath()
@ -1311,7 +1310,10 @@ class MainWindow(QMainWindow, WindowMixin):
dlg.setOption(QFileDialog.DontUseNativeDialog, False) dlg.setOption(QFileDialog.DontUseNativeDialog, False)
if dlg.exec_(): if dlg.exec_():
fullFilePath = ustr(dlg.selectedFiles()[0]) 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 '' return ''
def _saveFile(self, annotationFilePath): def _saveFile(self, annotationFilePath):

View File

Before

Width:  |  Height:  |  Size: 257 KiB

After

Width:  |  Height:  |  Size: 257 KiB

View File

@ -12,7 +12,7 @@ class TestPascalVocRW(unittest.TestCase):
from pascal_voc_io import PascalVocReader from pascal_voc_io import PascalVocReader
# Test Write/Read # 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 difficult = 1
writer.addBndBox(60, 40, 430, 504, 'person', difficult) writer.addBndBox(60, 40, 430, 504, 'person', difficult)
writer.addBndBox(113, 40, 450, 403, 'face', difficult) writer.addBndBox(113, 40, 450, 403, 'face', difficult)