Add EXIF rotation to YOLOv5 Hub inference (#3852)
* rotating an image according to its exif tag * Update common.py * Update datasets.py * Update datasets.py faster * delete extraneous gpg file * Update common.py Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
1 parent
4717a3b038
commit
831773f5a2
2 files changed
+31
-4
No files matched your search
@@ -64,6 +64,32 @@ def exif_size(img):
|
||||
return s
|
||||
|
||||
|
||||
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
|
||||
|
||||
:param image: The image to transpose.
|
||||
:return: An image.
|
||||
"""
|
||||
exif = image.getexif()
|
||||
orientation = exif.get(0x0112, 1) # default 1
|
||||
if orientation > 1:
|
||||
method = {2: Image.FLIP_LEFT_RIGHT,
|
||||
3: Image.ROTATE_180,
|
||||
4: Image.FLIP_TOP_BOTTOM,
|
||||
5: Image.TRANSPOSE,
|
||||
6: Image.ROTATE_270,
|
||||
7: Image.TRANSVERSE,
|
||||
8: Image.ROTATE_90,
|
||||
}.get(orientation)
|
||||
if method is not None:
|
||||
image = image.transpose(method)
|
||||
del exif[0x0112]
|
||||
image.info["exif"] = exif.tobytes()
|
||||
return image
|
||||
|
||||
|
||||
def create_dataloader(path, imgsz, batch_size, stride, single_cls=False, hyp=None, augment=False, cache=False, pad=0.0,
|
||||
rect=False, rank=-1, workers=8, image_weights=False, quad=False, prefix=''):
|
||||
# Make sure only the first process in DDP process the dataset first, and the following others can use the cache
|
||||
|
||||
Reference in new issue
Block a user