Skip to content

Commit

Permalink
load image from file storage added
Browse files Browse the repository at this point in the history
  • Loading branch information
serengil committed Nov 10, 2024
1 parent b19fce5 commit 6db41ae
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions deepface/commons/image_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import numpy as np
import cv2
from PIL import Image
from werkzeug.datastructures import FileStorage


def list_images(path: str) -> List[str]:
Expand Down Expand Up @@ -133,6 +134,21 @@ def load_image_from_base64(uri: str) -> np.ndarray:
return img_bgr


def load_image_from_file_storage(file: FileStorage) -> np.ndarray:
"""
Loads an image from a FileStorage object and decodes it into an OpenCV image.
Args:
file (FileStorage): The FileStorage object containing the image file.
Returns:
img (np.ndarray): The decoded image as a numpy array (OpenCV format).
"""
file_bytes = np.frombuffer(file.read(), np.uint8)
image = cv2.imdecode(file_bytes, cv2.IMREAD_COLOR)
if image is None:
raise ValueError("Failed to decode image")
return image


def load_image_from_web(url: str) -> np.ndarray:
"""
Loading an image from web
Expand Down

0 comments on commit 6db41ae

Please sign in to comment.