File size: 1,417 Bytes
bbc3fdf 892fa81 bbc3fdf 892fa81 bbc3fdf 892fa81 bbc3fdf 892fa81 bbc3fdf 892fa81 bbc3fdf 892fa81 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | """
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",
]
|