assets_test.py 959 B

12345678910111213141516171819202122232425262728293031323334353637
  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. img = cv2.imdecode(fromfile(file, dtype=uint8), -1)
  10. img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
  11. height, width, channels = img.shape
  12. if height != 720 or width != 1280:
  13. logger.error(f'Image size is {height}x{width}, not 720x1280')
  14. return None
  15. return img
  16. def detect_image(file: str, targe: RuleImage) -> bool:
  17. img = load_image(file)
  18. return targe.match(img)
  19. # 图片文件路径 可以是相对路径
  20. IMAGE_FILE = './log/error/1704971960417/2024-01-11_19-19-20-403213.png'
  21. if __name__ == '__main__':
  22. from tasks.KekkaiActivation.assets import KekkaiActivationAssets
  23. targe = KekkaiActivationAssets.I_A_HARVEST_FISH_6
  24. print(detect_image(IMAGE_FILE, targe))