face-intel / utils /image.py
Marwan
Restructure + add reverse face search (PimEyes-style)
f5eeb1c
Raw
History Blame Contribute Delete
1.42 kB
"""
utils.image — backward-compatibility shim.
All logic has moved to cores.vision. This module re-exports the
public API so existing imports (from utils.image import ...) continue
to work during the transition.
New code should import directly from cores.vision.
"""
from __future__ import annotations
# Re-export everything from cores.vision for backward compatibility
from cores.vision import (
bytes_to_numpy,
base64_to_numpy,
numpy_to_base64,
BBox,
crop_region as crop_face,
resize_with_aspect,
draw_boxes,
sha256_image as image_hash,
sha256_bytes as bytes_hash,
url_to_numpy,
url_to_bytes,
)
from pathlib import Path
import cv2
def save_image(img, path: Path, fmt: str = ".jpg") -> Path:
"""Save an image to disk."""
path = Path(path)
path.parent.mkdir(parents=True, exist_ok=True)
cv2.imwrite(str(path), img)
return path
def validate_image_file(path: Path) -> bool:
"""Validate that a file is a readable image (PIL verify)."""
try:
from PIL import Image
with Image.open(path) as im:
im.verify()
return True
except Exception:
return False
__all__ = [
"bytes_to_numpy", "base64_to_numpy", "numpy_to_base64",
"save_image", "image_hash", "bytes_hash", "BBox",
"crop_face", "resize_with_aspect", "url_to_numpy", "url_to_bytes",
"validate_image_file", "draw_boxes",
]