StarRailCopilot/module/base/template.py
LmeSzinc 061077c690 Fix: 修复一些bug
- 修复了日常结束后不收菜的问题
- 修复登录
- 增加不能使用潜艇的地图的覆盖设置
- 修复了因图片不更新导致二队不会跳过阵容检查的问题
- 修复了一些过场图导致进入战斗判断错误的问题
2020-04-12 20:28:31 +08:00

42 lines
1.0 KiB
Python

import cv2
import numpy as np
from PIL import Image
class Template:
def __init__(self, file):
"""
Args:
file (str): Filepath of template file.
"""
self.file = file
self.image = np.array(Image.open(file))
def match(self, image, similarity=0.85):
"""
Args:
image:
similarity (float): 0 to 1.
Returns:
bool: If matches.
"""
res = cv2.matchTemplate(np.array(image), self.image, cv2.TM_CCOEFF_NORMED)
_, sim, _, _ = cv2.minMaxLoc(res)
# print(self.file, sim)
return sim > similarity
def match_multi(self, image, similarity=0.85):
"""
Args:
image:
similarity (float): 0 to 1.
Returns:
np.ndarray: np.array([[x0, y0], [x1, y1])
"""
result = cv2.matchTemplate(np.array(image), self.image, cv2.TM_CCOEFF_NORMED)
result = np.array(np.where(result > similarity)).T
return result