27 lines
801 B
Python
27 lines
801 B
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
import cv2
|
|
import numpy as np
|
|
|
|
|
|
def load_image(path: str | Path, *, grayscale: bool = False) -> np.ndarray:
|
|
image_path = Path(path)
|
|
if not image_path.exists():
|
|
raise FileNotFoundError(f"image fixture does not exist: {image_path}")
|
|
|
|
flag = cv2.IMREAD_GRAYSCALE if grayscale else cv2.IMREAD_COLOR
|
|
image = cv2.imread(str(image_path), flag)
|
|
if image is None:
|
|
raise ValueError(f"OpenCV could not read image fixture: {image_path}")
|
|
return image
|
|
|
|
|
|
def load_screenshot(name: str, root: str | Path = "fixtures/screenshots") -> np.ndarray:
|
|
return load_image(Path(root) / name)
|
|
|
|
|
|
def load_template(name: str, root: str | Path = "fixtures/templates") -> np.ndarray:
|
|
return load_image(Path(root) / name)
|