assets_test.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. return targe.match(img)
  20. def detect_ocr(file: str, target: RuleOcr):
  21. img = load_image(file)
  22. return target.ocr(img)
  23. # 图片文件路径 可以是相对路径
  24. IMAGE_FILE = './log/error/1705350270552/2024-01-16_04-24-30-481597.png'
  25. if __name__ == '__main__':
  26. from tasks.KekkaiActivation.assets import KekkaiActivationAssets
  27. targe = KekkaiActivationAssets.I_A_INVITE
  28. print(detect_image(IMAGE_FILE, targe))
  29. # from tasks.KekkaiActivation.assets import KekkaiActivationAssets
  30. # target = KekkaiActivationAssets.O_CARD_ALL_TIME
  31. # print(detect_ocr(IMAGE_FILE, target))