mirror of
https://github.com/LmeSzinc/StarRailCopilot.git
synced 2024-11-27 02:27:12 +00:00
061077c690
- 修复了日常结束后不收菜的问题 - 修复登录 - 增加不能使用潜艇的地图的覆盖设置 - 修复了因图片不更新导致二队不会跳过阵容检查的问题 - 修复了一些过场图导致进入战斗判断错误的问题
42 lines
1.0 KiB
Python
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
|