Skip to content

Commit f40932c

Browse files
committed
♻️ refactor(image-matching): 优化图片匹配过滤逻辑
- 改进子节点匹配精度,要求后缀以'-'开头,避免误匹配 (如 "A-1" 匹配 "A-10") - 将跳过自身匹配的逻辑提前,提高过滤效率 - 保持后缀长度限制,确保只匹配紧邻的子节点
1 parent 348e3e3 commit f40932c

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

src/tasks/fullauto/ImportTask.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -301,19 +301,36 @@ def match_map(self, index, max_conf=0.0, pattern=None): # 建议给 max_conf
301301

302302
for name, template_gray in self.img.items():
303303
# --- 过滤逻辑 ---
304-
# 逻辑 1: 起始状态(index is None),跳过以字母结尾的图(假设字母结尾是后续步骤)
304+
# 逻辑 1: 起始状态 (index is None)
305305
if index is None and not pattern.search(name):
306306
continue
307307

308308
if index is not None:
309-
# 逻辑 2: 如果有前置节点,只匹配包含前置节点名且长度差异不大的图 (寻找子节点/后继节点)
310-
# 例如:former="Map1", current check="Map1_A" (Len diff 2) -> OK
311-
if index not in name or (len(name) - len(index) > 4):
312-
continue
313-
# 逻辑 3: 不匹配自己
309+
# 逻辑 2: 不匹配自己 (先判断这个效率最高)
314310
if index == name:
315311
continue
316312

313+
# 逻辑 3: 严格的前缀匹配
314+
315+
# 1. 必须是以 index 开头
316+
if not name.startswith(index):
317+
continue
318+
319+
# 2. 获取去掉 index 后的剩余部分
320+
# 例如: index="A-1", name="A-1-1" -> suffix="-1"
321+
# 例如: index="A-1", name="A-10" -> suffix="0"
322+
suffix = name[len(index):]
323+
324+
# 3. 检查分隔符:如果不是以 '-' 开头,说明不是层级递进,而是数字扩展 (如 1 -> 10)
325+
# 这一步阻止了 "60角色-A-1-1" 匹配到 "60角色-A-1-10"
326+
if not suffix.startswith('-'):
327+
continue
328+
329+
# 4. 长度限制 (防止跳太远,保持原有的逻辑)
330+
# 这里的 len(suffix) 等同于 len(name) - len(index)
331+
if len(suffix) > 4:
332+
continue
333+
317334
count += 1
318335

319336
# 执行匹配

0 commit comments

Comments
 (0)