diff --git a/labelImg.py b/labelImg.py index 657163e1..d9983a59 100755 --- a/labelImg.py +++ b/labelImg.py @@ -1046,7 +1046,10 @@ class MainWindow(QMainWindow, WindowMixin): self.labelFile = None 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(): self.errorMessage(u'Error opening file', u"

Make sure %s is a valid image file." % unicodeFilePath) @@ -1518,8 +1521,9 @@ def inverted(color): def read(filename, default=None): try: - with open(filename, 'rb') as f: - return f.read() + reader = QImageReader(filename) + reader.setAutoTransform(True) + return reader.read() except: return default diff --git a/libs/labelFile.py b/libs/labelFile.py index ebcca266..b335f818 100644 --- a/libs/labelFile.py +++ b/libs/labelFile.py @@ -43,8 +43,11 @@ class LabelFile(object): #imgFileNameWithoutExt = os.path.splitext(imgFileName)[0] # Read from file path because self.imageData might be empty if saving to # Pascal format - image = QImage() - image.load(imagePath) + if isinstance(imageData, QImage): + image = imageData + else: + image = QImage() + image.load(imagePath) imageShape = [image.height(), image.width(), 1 if image.isGrayscale() else 3] writer = PascalVocWriter(imgFolderName, imgFileName, @@ -70,8 +73,11 @@ class LabelFile(object): #imgFileNameWithoutExt = os.path.splitext(imgFileName)[0] # Read from file path because self.imageData might be empty if saving to # Pascal format - image = QImage() - image.load(imagePath) + if isinstance(imageData, QImage): + image = imageData + else: + image = QImage() + image.load(imagePath) imageShape = [image.height(), image.width(), 1 if image.isGrayscale() else 3] writer = YOLOWriter(imgFolderName, imgFileName,