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):
|
def openNextImg(self, _value=False):
|
||||||
# Proceding next image without dialog if having any label
|
# Proceding next image without dialog if having any label
|
||||||
if self.autoSaving is True and self.defaultSaveDir is not None:
|
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()
|
self.saveFile()
|
||||||
|
|
||||||
if not self.mayContinue():
|
if not self.mayContinue():
|
||||||
@ -1021,24 +1021,21 @@ class MainWindow(QMainWindow, WindowMixin):
|
|||||||
self.loadFile(filename)
|
self.loadFile(filename)
|
||||||
|
|
||||||
def saveFile(self, _value=False):
|
def saveFile(self, _value=False):
|
||||||
assert not self.image.isNull(), "cannot save empty image"
|
if self.defaultSaveDir is not None and len(str(self.defaultSaveDir)):
|
||||||
if self.hasLabels():
|
# print('handle the image:' + self.filePath)
|
||||||
if self.defaultSaveDir is not None and len(str(self.defaultSaveDir)):
|
imgFileName = os.path.basename(self.filePath)
|
||||||
# print('handle the image:' + self.filePath)
|
savedFileName = os.path.splitext(
|
||||||
imgFileName = os.path.basename(self.filePath)
|
imgFileName)[0] + LabelFile.suffix
|
||||||
savedFileName = os.path.splitext(
|
savedPath = os.path.join(
|
||||||
imgFileName)[0] + LabelFile.suffix
|
str(self.defaultSaveDir), savedFileName)
|
||||||
savedPath = os.path.join(
|
self._saveFile(savedPath)
|
||||||
str(self.defaultSaveDir), savedFileName)
|
else:
|
||||||
self._saveFile(savedPath)
|
self._saveFile(self.filePath if self.labelFile
|
||||||
else:
|
else self.saveFileDialog())
|
||||||
self._saveFile(self.filePath if self.labelFile
|
|
||||||
else self.saveFileDialog())
|
|
||||||
|
|
||||||
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"
|
||||||
if self.hasLabels():
|
self._saveFile(self.saveFileDialog())
|
||||||
self._saveFile(self.saveFileDialog())
|
|
||||||
|
|
||||||
def saveFileDialog(self):
|
def saveFileDialog(self):
|
||||||
caption = '%s - Choose File' % __appname__
|
caption = '%s - Choose File' % __appname__
|
||||||
@ -1069,14 +1066,6 @@ class MainWindow(QMainWindow, WindowMixin):
|
|||||||
self.canvas.setEnabled(False)
|
self.canvas.setEnabled(False)
|
||||||
self.actions.saveAs.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):
|
def mayContinue(self):
|
||||||
return not (self.dirty and not self.discardChangesDialog())
|
return not (self.dirty and not self.discardChangesDialog())
|
||||||
|
|
||||||
|
|||||||
@ -41,16 +41,13 @@ class LabelFile(object):
|
|||||||
1 if image.isGrayscale() else 3]
|
1 if image.isGrayscale() else 3]
|
||||||
writer = PascalVocWriter(imgFolderName, imgFileNameWithoutExt,
|
writer = PascalVocWriter(imgFolderName, imgFileNameWithoutExt,
|
||||||
imageShape, localImgPath=imagePath)
|
imageShape, localImgPath=imagePath)
|
||||||
bSave = False
|
|
||||||
for shape in shapes:
|
for shape in shapes:
|
||||||
points = shape['points']
|
points = shape['points']
|
||||||
label = shape['label']
|
label = shape['label']
|
||||||
bndbox = LabelFile.convertPoints2BndBox(points)
|
bndbox = LabelFile.convertPoints2BndBox(points)
|
||||||
writer.addBndBox(bndbox[0], bndbox[1], bndbox[2], bndbox[3], label)
|
writer.addBndBox(bndbox[0], bndbox[1], bndbox[2], bndbox[3], label)
|
||||||
bSave = True
|
|
||||||
|
|
||||||
if bSave:
|
writer.save(targetFile=filename)
|
||||||
writer.save(targetFile=filename)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
@ -35,8 +35,7 @@ class PascalVocWriter:
|
|||||||
# Check conditions
|
# Check conditions
|
||||||
if self.filename is None or \
|
if self.filename is None or \
|
||||||
self.foldername is None or \
|
self.foldername is None or \
|
||||||
self.imgSize is None or \
|
self.imgSize is None:
|
||||||
len(self.boxlist) <= 0:
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
top = Element('annotation')
|
top = Element('annotation')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user