mirror of
https://github.com/LmeSzinc/StarRailCopilot.git
synced 2024-11-30 11:19:30 +00:00
8eab19ab04
- 修复了没有阵容锁定选项时会卡住的问题 - 修复了非周回时频繁报Arrive with unexpected result的问题 - 清理了一些无用的asset
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, similarity)
|
|
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
|