Read via QImageReader (#650)

* Now read via QImageReader

* Remove comment-out unused lines
This commit is contained in:
EuihyunLee 2020-09-27 03:03:04 +09:00 committed by GitHub
parent 08db03a36d
commit 058d7a7e80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 7 deletions

View File

@ -1046,7 +1046,10 @@ class MainWindow(QMainWindow, WindowMixin):
self.labelFile = None self.labelFile = None
self.canvas.verified = False self.canvas.verified = False
image = QImage.fromData(self.imageData) if isinstance(self.imageData, QImage):
image = self.imageData
else:
image = QImage.fromData(self.imageData)
if image.isNull(): if image.isNull():
self.errorMessage(u'Error opening file', self.errorMessage(u'Error opening file',
u"<p>Make sure <i>%s</i> is a valid image file." % unicodeFilePath) u"<p>Make sure <i>%s</i> is a valid image file." % unicodeFilePath)
@ -1518,8 +1521,9 @@ def inverted(color):
def read(filename, default=None): def read(filename, default=None):
try: try:
with open(filename, 'rb') as f: reader = QImageReader(filename)
return f.read() reader.setAutoTransform(True)
return reader.read()
except: except:
return default return default

View File

@ -43,8 +43,11 @@ class LabelFile(object):
#imgFileNameWithoutExt = os.path.splitext(imgFileName)[0] #imgFileNameWithoutExt = os.path.splitext(imgFileName)[0]
# Read from file path because self.imageData might be empty if saving to # Read from file path because self.imageData might be empty if saving to
# Pascal format # Pascal format
image = QImage() if isinstance(imageData, QImage):
image.load(imagePath) image = imageData
else:
image = QImage()
image.load(imagePath)
imageShape = [image.height(), image.width(), imageShape = [image.height(), image.width(),
1 if image.isGrayscale() else 3] 1 if image.isGrayscale() else 3]
writer = PascalVocWriter(imgFolderName, imgFileName, writer = PascalVocWriter(imgFolderName, imgFileName,
@ -70,8 +73,11 @@ class LabelFile(object):
#imgFileNameWithoutExt = os.path.splitext(imgFileName)[0] #imgFileNameWithoutExt = os.path.splitext(imgFileName)[0]
# Read from file path because self.imageData might be empty if saving to # Read from file path because self.imageData might be empty if saving to
# Pascal format # Pascal format
image = QImage() if isinstance(imageData, QImage):
image.load(imagePath) image = imageData
else:
image = QImage()
image.load(imagePath)
imageShape = [image.height(), image.width(), imageShape = [image.height(), image.width(),
1 if image.isGrayscale() else 3] 1 if image.isGrayscale() else 3]
writer = YOLOWriter(imgFolderName, imgFileName, writer = YOLOWriter(imgFolderName, imgFileName,