Commit 88652224 authored by Immanuel Weber's avatar Immanuel Weber

fix loading of old style files + add to anno files

parent e7c9aed2
......@@ -794,7 +794,7 @@ class MainWindow(QMainWindow, WindowMixin):
annotationFilePath += XML_EXT
print ('Img: ' + self.filePath + ' -> Its xml: ' + annotationFilePath)
self.labelFile.savePascalVocFormat(annotationFilePath, shapes, self.filePath, self.imageData,
self.lineColor.getRgb(), self.fillColor.getRgb())
self.lineColor.getRgb(), self.fillColor.getRgb(), version=__version__)
elif self.usingYoloFormat is True:
if annotationFilePath[-4:] != ".txt":
annotationFilePath += TXT_EXT
......
......@@ -28,9 +28,11 @@ class LabelFile(object):
self.imagePath = None
self.imageData = None
self.verified = False
self.lineColor = (255, 255, 255)
self.fillColor = (255, 255, 255)
def savePascalVocFormat(self, filename, shapes, imagePath, imageData,
lineColor=None, fillColor=None, databaseSrc=None):
lineColor=None, fillColor=None, databaseSrc=None, version=None):
imgFolderPath = os.path.dirname(imagePath)
imgFolderName = os.path.split(imgFolderPath)[-1]
imgFileName = os.path.basename(imagePath)
......@@ -42,7 +44,7 @@ class LabelFile(object):
imageShape = [image.height(), image.width(),
1 if image.isGrayscale() else 3]
writer = PascalVocWriter(imgFolderName, imgFileName,
imageShape, localImgPath=imagePath)
imageShape, localImgPath=imagePath, version=version)
writer.verified = self.verified
for shape in shapes:
......
......@@ -12,7 +12,7 @@ ENCODE_METHOD = 'utf-8'
class PascalVocWriter:
def __init__(self, foldername, filename, imgSize,databaseSrc='Unknown', localImgPath=None):
def __init__(self, foldername, filename, imgSize, databaseSrc='Unknown', localImgPath=None, version=None):
self.foldername = foldername
self.filename = filename
self.databaseSrc = databaseSrc
......@@ -20,6 +20,7 @@ class PascalVocWriter:
self.boxlist = []
self.localImgPath = localImgPath
self.verified = False
self.version = version
def prettify(self, elem):
"""
......@@ -59,6 +60,12 @@ class PascalVocWriter:
source = SubElement(top, 'source')
database = SubElement(source, 'database')
database.text = self.databaseSrc
if self.version is not None:
tool = SubElement(top, 'tool')
name = SubElement(tool, 'name')
name.text = "labelImg-rotbox"
version = SubElement(tool, 'version')
version.text = self.version
size_part = SubElement(top, 'size')
width = SubElement(size_part, 'width')
......@@ -167,12 +174,20 @@ class PascalVocReader:
ymin = int(bndbox.find('ymin').text)
xmax = int(bndbox.find('xmax').text)
ymax = int(bndbox.find('ymax').text)
cx = float(box.find('cx').text)
cy = float(box.find('cy').text)
width = float(box.find('width').text)
height = float(box.find('height').text)
angle = float(box.find('angle').text)
box = ((cx, cy), (width, height), angle)
if box is not None:
cx = float(box.find('cx').text)
cy = float(box.find('cy').text)
width = float(box.find('width').text)
height = float(box.find('height').text)
angle = float(box.find('angle').text)
box = ((cx, cy), (width, height), angle)
else:
# fallback for old versions
cx = float(xmin + xmax) / 2.0
cy = float(ymin + ymax) / 2.0
width = float(xmax - xmin)
height = float(ymax - ymin)
box = ((cx, cy), (width, height), 0.0)
bbox_points = [(xmin, ymin), (xmax, ymin), (xmax, ymax), (xmin, ymax)]
self.shapes.append((label, bbox_points, box, None, None, difficult))
......
__version_info__ = ('1', '7', '0')
__version_info__ = ('1', '7', '0-custom')
__version__ = '.'.join(__version_info__)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment