assets_test.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import cv2
  2. import numpy as np
  3. from numpy import float32, int32, uint8, fromfile
  4. from pathlib import Path
  5. from module.logger import logger
  6. from module.atom.image import RuleImage
  7. from module.atom.ocr import RuleOcr
  8. def load_image(file: str):
  9. file = Path(file)
  10. img = cv2.imdecode(fromfile(file, dtype=uint8), -1)
  11. img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
  12. height, width, channels = img.shape
  13. if height != 720 or width != 1280:
  14. logger.error(f'Image size is {height}x{width}, not 720x1280')
  15. return None
  16. return img
  17. def detect_image(file: str, targe: RuleImage) -> bool:
  18. img = load_image(file)
  19. result = targe.test_match(img)
  20. logger.info(f'[{targe.name}]: {result}')
  21. return result
  22. def detect_ocr(file: str, target: RuleOcr):
  23. img = load_image(file)
  24. return target.ocr(img)
  25. # 图片文件路径 可以是相对路径
  26. IMAGE_FILE = r"C:\Users\萌萌哒\Desktop\QQ20250105-160854.png"
  27. if __name__ == '__main__':
  28. from tasks.KittyShop.script_task import ScriptTask
  29. targe = ScriptTask.I_MAIN_BUSY_2
  30. print(detect_image(IMAGE_FILE, targe))
  31. # ocr demo
  32. # from tasks.KekkaiActivation.assets import KekkaiActivationAssets
  33. # target = KekkaiActivationAssets.O_CARD_ALL_TIME
  34. # print(detect_ocr(IMAGE_FILE, target))