Procházet zdrojové kódy

take EXIF orientation tags into account when fixing corrupt images (#5270)

* take EXIF orientation tags into account when fixing corrupt images

* fit 120 char

* sort imports

* Update local exif_transpose comment

We have a local inplace version that is faster than the official as the image is not copied. AutoShape() uses this for Hub models, but here it is not important as the datasets.py usage is infrequent (AutoShape() it is applied every image).

* Update datasets.py

Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
modifyDataloader
jdfr GitHub před 2 roky
rodič
revize
15e8c4c15b
V databázi nebyl nalezen žádný známý klíč pro tento podpis ID GPG klíče: 4AEE18F83AFDEB23
1 změnil soubory, kde provedl 3 přidání a 3 odebrání
  1. +3
    -3
      utils/datasets.py

+ 3
- 3
utils/datasets.py Zobrazit soubor

@@ -22,7 +22,7 @@ import numpy as np
import torch
import torch.nn.functional as F
import yaml
from PIL import Image, ExifTags
from PIL import Image, ImageOps, ExifTags
from torch.utils.data import Dataset
from tqdm import tqdm

@@ -69,7 +69,7 @@ def exif_size(img):
def exif_transpose(image):
"""
Transpose a PIL image accordingly if it has an EXIF Orientation tag.
From https://github.com/python-pillow/Pillow/blob/master/src/PIL/ImageOps.py
Inplace version of https://github.com/python-pillow/Pillow/blob/master/src/PIL/ImageOps.py exif_transpose()

:param image: The image to transpose.
:return: An image.
@@ -896,7 +896,7 @@ def verify_image_label(args):
with open(im_file, 'rb') as f:
f.seek(-2, 2)
if f.read() != b'\xff\xd9': # corrupt JPEG
Image.open(im_file).save(im_file, format='JPEG', subsampling=0, quality=100) # re-save image
ImageOps.exif_transpose(Image.open(im_file)).save(im_file, 'JPEG', subsampling=0, quality=100)
msg = f'{prefix}WARNING: {im_file}: corrupt JPEG restored and saved'

# verify labels

Načítá se…
Zrušit
Uložit