|
@@ -157,6 +157,9 @@ class RuleImage(RuleImageMallResourceMixin):
|
|
|
if mat is None or mat.shape[0] == 0 or mat.shape[1] == 0:
|
|
if mat is None or mat.shape[0] == 0 or mat.shape[1] == 0:
|
|
|
logger.error(f"Template image is invalid: {mat.shape}")
|
|
logger.error(f"Template image is invalid: {mat.shape}")
|
|
|
return False # 模板无效,匹配失败
|
|
return False # 模板无效,匹配失败
|
|
|
|
|
+ if mat.shape[0] > source.shape[0] or mat.shape[1] > source.shape[1]:
|
|
|
|
|
+ # 模板大于源图,视为无效匹配(避免 matchTemplate 的异常行为)
|
|
|
|
|
+ return False
|
|
|
|
|
|
|
|
res = cv2.matchTemplate(source, mat, cv2.TM_CCOEFF_NORMED)
|
|
res = cv2.matchTemplate(source, mat, cv2.TM_CCOEFF_NORMED)
|
|
|
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res) # 最小匹配度,最大匹配度,最小匹配度的坐标,最大匹配度的坐标
|
|
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res) # 最小匹配度,最大匹配度,最小匹配度的坐标,最大匹配度的坐标
|
|
@@ -200,6 +203,9 @@ class RuleImage(RuleImageMallResourceMixin):
|
|
|
if mat is None or mat.shape[0] == 0 or mat.shape[1] == 0:
|
|
if mat is None or mat.shape[0] == 0 or mat.shape[1] == 0:
|
|
|
logger.error(f"Template image is invalid: {mat.shape}")
|
|
logger.error(f"Template image is invalid: {mat.shape}")
|
|
|
return False
|
|
return False
|
|
|
|
|
+ if mat.shape[0] > source.shape[0] or mat.shape[1] > source.shape[1]:
|
|
|
|
|
+ # 模板大于源图,视为无效匹配(避免 matchTemplate 的异常行为)
|
|
|
|
|
+ return False
|
|
|
|
|
|
|
|
# 预计算模板尺寸
|
|
# 预计算模板尺寸
|
|
|
mat_h, mat_w = mat.shape[:2]
|
|
mat_h, mat_w = mat.shape[:2]
|