diff --git a/labelImg.py b/labelImg.py index d9df7717..a00e63a6 100755 --- a/labelImg.py +++ b/labelImg.py @@ -986,7 +986,7 @@ class MainWindow(QMainWindow, WindowMixin): def openNextImg(self, _value=False): # Proceding next image without dialog if having any label if self.autoSaving is True and self.defaultSaveDir is not None: - if self.dirty is True and self.hasLabels(): + if self.dirty is True: self.saveFile() if not self.mayContinue(): @@ -1021,24 +1021,21 @@ class MainWindow(QMainWindow, WindowMixin): self.loadFile(filename) def saveFile(self, _value=False): - assert not self.image.isNull(), "cannot save empty image" - if self.hasLabels(): - if self.defaultSaveDir is not None and len(str(self.defaultSaveDir)): - # print('handle the image:' + self.filePath) - imgFileName = os.path.basename(self.filePath) - savedFileName = os.path.splitext( - imgFileName)[0] + LabelFile.suffix - savedPath = os.path.join( - str(self.defaultSaveDir), savedFileName) - self._saveFile(savedPath) - else: - self._saveFile(self.filePath if self.labelFile - else self.saveFileDialog()) + if self.defaultSaveDir is not None and len(str(self.defaultSaveDir)): + # print('handle the image:' + self.filePath) + imgFileName = os.path.basename(self.filePath) + savedFileName = os.path.splitext( + imgFileName)[0] + LabelFile.suffix + savedPath = os.path.join( + str(self.defaultSaveDir), savedFileName) + self._saveFile(savedPath) + else: + self._saveFile(self.filePath if self.labelFile + else self.saveFileDialog()) def saveFileAs(self, _value=False): assert not self.image.isNull(), "cannot save empty image" - if self.hasLabels(): - self._saveFile(self.saveFileDialog()) + self._saveFile(self.saveFileDialog()) def saveFileDialog(self): caption = '%s - Choose File' % __appname__ @@ -1069,14 +1066,6 @@ class MainWindow(QMainWindow, WindowMixin): self.canvas.setEnabled(False) self.actions.saveAs.setEnabled(False) - # Message Dialogs. # - def hasLabels(self): - if not self.itemsToShapes: - self.errorMessage(u'No objects labeled', - u'You must label at least one object to save the file.') - return False - return True - def mayContinue(self): return not (self.dirty and not self.discardChangesDialog()) diff --git a/libs/labelFile.py b/libs/labelFile.py index 6e20891c..2847a3b1 100644 --- a/libs/labelFile.py +++ b/libs/labelFile.py @@ -41,16 +41,13 @@ class LabelFile(object): 1 if image.isGrayscale() else 3] writer = PascalVocWriter(imgFolderName, imgFileNameWithoutExt, imageShape, localImgPath=imagePath) - bSave = False for shape in shapes: points = shape['points'] label = shape['label'] bndbox = LabelFile.convertPoints2BndBox(points) writer.addBndBox(bndbox[0], bndbox[1], bndbox[2], bndbox[3], label) - bSave = True - if bSave: - writer.save(targetFile=filename) + writer.save(targetFile=filename) return @staticmethod diff --git a/libs/pascal_voc_io.py b/libs/pascal_voc_io.py index 3999661c..ec7d02dd 100644 --- a/libs/pascal_voc_io.py +++ b/libs/pascal_voc_io.py @@ -35,8 +35,7 @@ class PascalVocWriter: # Check conditions if self.filename is None or \ self.foldername is None or \ - self.imgSize is None or \ - len(self.boxlist) <= 0: + self.imgSize is None: return None top = Element('annotation')