Save an annotation file when there is no ROI
This commit is contained in:
parent
c5c2a34a39
commit
77d5fae05f
37
labelImg.py
37
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())
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user