Skip to content

Commit

Permalink
Improve performance for loading large image files by optimizing proce…
Browse files Browse the repository at this point in the history
…ssing steps (#329)
  • Loading branch information
CVHub520 committed Mar 21, 2024
1 parent 59c8956 commit a48bb0e
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions anylabeling/views/labeling/label_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,13 @@ def __init__(self, filename=None, image_dir=None):
self.filename = filename

@staticmethod
def load_image_file(filename):
def load_image_file(filename, default=None):
try:
image_pil = PIL.Image.open(filename)
except IOError:
with open(filename, 'rb') as f:
return f.read()
except:
logger.error("Failed opening image file: %s", filename)
return None

# apply orientation to image according to exif
image_pil = utils.apply_exif_orientation(image_pil)

with io.BytesIO() as f:
ext = osp.splitext(filename)[1].lower()
if ext in [".jpg", ".jpeg"]:
image_pil = image_pil.convert("RGB")
img_format = "JPEG"
else:
img_format = "PNG"
image_pil.save(f, format=img_format)
f.seek(0)
return f.read()
return default

def load(self, filename):
keys = [
Expand Down

0 comments on commit a48bb0e

Please sign in to comment.