| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- import cv2
- import numpy as np
- from numpy import float32, int32, uint8, fromfile
- from pathlib import Path
- from module.logger import logger
- from module.atom.image import RuleImage
- from module.atom.ocr import RuleOcr
- def load_image(file: str):
- file = Path(file)
- img = cv2.imdecode(fromfile(file, dtype=uint8), -1)
- img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
- height, width, channels = img.shape
- if height != 720 or width != 1280:
- logger.error(f'Image size is {height}x{width}, not 720x1280')
- return None
- return img
- def detect_image(file: str, targe: RuleImage) -> bool:
- img = load_image(file)
- result = targe.test_match(img)
- logger.info(f'[{targe.name}]: {result}')
- return result
- def detect_ocr(file: str, target: RuleOcr):
- img = load_image(file)
- return target.ocr(img)
- # 图片文件路径 可以是相对路径
- IMAGE_FILE = r"C:\Users\萌萌哒\Desktop\349772746-36423909-af3d-4d9c-bae4-9d2597e2ecda.png"
- if __name__ == '__main__':
- from tasks.RyouToppa.assets import RyouToppaAssets
- from tasks.GameUi.assets import GameUiAssets
- targe = GameUiAssets.I_MAIN_GOTO_GUILD
- print(detect_image(IMAGE_FILE, targe))
- # ocr demo
- # from tasks.KekkaiActivation.assets import KekkaiActivationAssets
- # target = KekkaiActivationAssets.O_CARD_ALL_TIME
- # print(detect_ocr(IMAGE_FILE, target))
|