-
Notifications
You must be signed in to change notification settings - Fork 217
/
Copy pathassets_test.py
46 lines (34 loc) · 1.29 KB
/
assets_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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\Neptine\Desktop\404528170-67ec447a-cc2c-4c62-b253-51e383f6a863.png"
if __name__ == '__main__':
from tasks.SoulsTidy.script_task import ScriptTask
targe = ScriptTask.I_UI_CONFIRM
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))