mirror of
https://github.com/serengil/deepface.git
synced 2025-06-07 12:05:22 +00:00
image_exts and pil_exts are now global variables and are now named as IMAGE_EXTS and PIL_EXTS to match Python naming conventions.
This commit is contained in:
parent
6a7505269c
commit
83031a427d
@ -14,6 +14,10 @@ from PIL import Image
|
|||||||
from werkzeug.datastructures import FileStorage
|
from werkzeug.datastructures import FileStorage
|
||||||
|
|
||||||
|
|
||||||
|
IMAGE_EXTS = {".jpg", ".jpeg", ".png"}
|
||||||
|
PIL_EXTS = {"jpeg", "png"}
|
||||||
|
|
||||||
|
|
||||||
def list_images(path: str) -> List[str]:
|
def list_images(path: str) -> List[str]:
|
||||||
"""
|
"""
|
||||||
List images in a given path
|
List images in a given path
|
||||||
@ -23,14 +27,12 @@ def list_images(path: str) -> List[str]:
|
|||||||
images (list): list of exact image paths
|
images (list): list of exact image paths
|
||||||
"""
|
"""
|
||||||
images = []
|
images = []
|
||||||
image_exts = {".jpg", ".jpeg", ".png"}
|
|
||||||
pil_exts = {"jpeg", "png"}
|
|
||||||
for r, _, f in os.walk(path):
|
for r, _, f in os.walk(path):
|
||||||
for file in f:
|
for file in f:
|
||||||
if os.path.splitext(file)[1].lower() in image_exts:
|
if os.path.splitext(file)[1].lower() in IMAGE_EXTS:
|
||||||
exact_path = os.path.join(r, file)
|
exact_path = os.path.join(r, file)
|
||||||
with Image.open(exact_path) as img: # lazy
|
with Image.open(exact_path) as img: # lazy
|
||||||
if img.format.lower() in pil_exts:
|
if img.format.lower() in PIL_EXTS:
|
||||||
images.append(exact_path)
|
images.append(exact_path)
|
||||||
return images
|
return images
|
||||||
|
|
||||||
@ -43,14 +45,12 @@ def yield_images(path: str) -> Generator[str, None, None]:
|
|||||||
Yields:
|
Yields:
|
||||||
image (str): image path
|
image (str): image path
|
||||||
"""
|
"""
|
||||||
image_exts = {".jpg", ".jpeg", ".png"}
|
|
||||||
pil_exts = {"jpeg", "png"}
|
|
||||||
for r, _, f in os.walk(path):
|
for r, _, f in os.walk(path):
|
||||||
for file in f:
|
for file in f:
|
||||||
if os.path.splitext(file)[1].lower() in image_exts:
|
if os.path.splitext(file)[1].lower() in IMAGE_EXTS:
|
||||||
exact_path = os.path.join(r, file)
|
exact_path = os.path.join(r, file)
|
||||||
with Image.open(exact_path) as img: # lazy
|
with Image.open(exact_path) as img: # lazy
|
||||||
if img.format.lower() in pil_exts:
|
if img.format.lower() in PIL_EXTS:
|
||||||
yield exact_path
|
yield exact_path
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user