Load Pascal xml for each image if setting saved annotation folder
This commit is contained in:
parent
38c9cabb01
commit
3b01871851
24
labelImg.py
24
labelImg.py
@ -705,8 +705,10 @@ class MainWindow(QMainWindow, WindowMixin):
|
||||
|
||||
## Label xml file and show bound box according to its filename
|
||||
if self.usingPascalVocFormat is True and \
|
||||
self.changeSavedir is not None:
|
||||
print 'Try to load xml file to the image'
|
||||
self.defaultSaveDir is not None:
|
||||
basename = os.path.basename(self.filename).split('.')[:-1][0]
|
||||
xmlPath = os.path.join(self.defaultSaveDir, basename + '.xml')
|
||||
self.loadPascalXMLByFilename(xmlPath)
|
||||
|
||||
return True
|
||||
return False
|
||||
@ -813,18 +815,14 @@ class MainWindow(QMainWindow, WindowMixin):
|
||||
|
||||
path = os.path.dirname(unicode(self.filename))\
|
||||
if self.filename else '.'
|
||||
|
||||
if self.usingPascalVocFormat:
|
||||
formats = ['*.%s' % unicode(fmt).lower()\
|
||||
for fmt in QImageReader.supportedImageFormats()]
|
||||
filters = "Open Annotation XML file (%s)" % \
|
||||
' '.join(formats + ['*.xml'])
|
||||
filename = unicode(QFileDialog.getOpenFileName(self,
|
||||
'%s - Choose a xml file' % __appname__, path, filters))
|
||||
|
||||
tVocParseReader = PascalVocReader(filename)
|
||||
shapes = tVocParseReader.getShapes()
|
||||
self.loadLabels(shapes)
|
||||
return
|
||||
self.loadPascalXMLByFilename(filename)
|
||||
|
||||
def openDir(self, _value=False):
|
||||
if not self.mayContinue():
|
||||
@ -1037,6 +1035,16 @@ class MainWindow(QMainWindow, WindowMixin):
|
||||
else:
|
||||
self.labelHist.append(line)
|
||||
|
||||
def loadPascalXMLByFilename(self, filename):
|
||||
if self.filename is None:
|
||||
return
|
||||
if os.path.exists(filename) is False:
|
||||
return
|
||||
|
||||
tVocParseReader = PascalVocReader(filename)
|
||||
shapes = tVocParseReader.getShapes()
|
||||
self.loadLabels(shapes)
|
||||
|
||||
class Settings(object):
|
||||
"""Convenience dict-like wrapper around QSettings."""
|
||||
def __init__(self, types=None):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user