scan, split, OCR, prepare for LLM
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

helpers.py 503B

12345678910111213141516171819
  1. from __future__ import annotations
  2. import tempfile
  3. from pathlib import Path
  4. import cv2
  5. import numpy as np
  6. def create_test_image(width: int = 400, height: int = 300) -> np.ndarray:
  7. image = np.zeros((height, width, 3), dtype=np.uint8)
  8. image[:, :] = (200, 200, 200)
  9. return image
  10. def image_to_path(image: np.ndarray, suffix: str = ".png") -> Path:
  11. with tempfile.NamedTemporaryFile(suffix=suffix, delete=False) as tmp:
  12. cv2.imwrite(tmp.name, image)
  13. return Path(tmp.name)