Save an annotation file when there is no ROI
This commit is contained in:
parent
c5c2a34a39
commit
77d5fae05f
13
labelImg.py
13
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,8 +1021,6 @@ 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.hasLabels():
|
|
||||||
if self.defaultSaveDir is not None and len(str(self.defaultSaveDir)):
|
if self.defaultSaveDir is not None and len(str(self.defaultSaveDir)):
|
||||||
# print('handle the image:' + self.filePath)
|
# print('handle the image:' + self.filePath)
|
||||||
imgFileName = os.path.basename(self.filePath)
|
imgFileName = os.path.basename(self.filePath)
|
||||||
@ -1037,7 +1035,6 @@ class MainWindow(QMainWindow, WindowMixin):
|
|||||||
|
|
||||||
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):
|
||||||
@ -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,15 +41,12 @@ 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
|
||||||
|
|
||||||
|
|||||||
@ -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