mirror of
https://github.com/serengil/deepface.git
synced 2025-06-06 11:35:21 +00:00
load image from file storage added
This commit is contained in:
parent
b19fce5f8d
commit
6db41ae3f2
@ -11,6 +11,7 @@ import requests
|
||||
import numpy as np
|
||||
import cv2
|
||||
from PIL import Image
|
||||
from werkzeug.datastructures import FileStorage
|
||||
|
||||
|
||||
def list_images(path: str) -> List[str]:
|
||||
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user