Skip to content

建议向 TemplateMatch 新增 template_negative 参数 #1371

Description

@isHarryh

功能描述 / Feature Description

此提案事实上是在 MaaEnd 开发群讨论过的“竞争性模板匹配”算法思想的一个最小化的特殊移植。

背景:

在游戏自动化实践过程中,常遇到一种情况,即需要匹配某个特定的图标,但待匹配的位置可能出现其他相似的图标,且后者是不希望被匹配上的。这种情况常出现在背包内物品图标识别中。

以一个真实案例为例,我希望在《终末地》抢委托任务中,识别“武陵调度券”的图标,但是,在同一个位置,可能出现“四号谷地调度券”,二者形态非常相似但长相略有不同。此时,如果我直接使用传统 TemplateMatch,是无法很好地实现“只选择武陵调度券”的,极有可能误选择另一物品图标,即使它的识别分数略低但高于设定的阈值。

template_negative 参数正是为此提出。它主要是通过引入对负面模板的额外识别,达到排除的效果。

建议 Pipeline 写法:

{
  "Node": {
    "recognition": "TemplateMatch",
    "template": [
      "WantedIcon.png"
    ],
    "template_negative": [
      "UnwantedIcon.png"
    ]
  }
}

建议算法逻辑:

当 MaaFW 检测到 ROI 内 $\exists$ 任意区域 $R_i=[x, y, w, h]$ 命中了任意 template(预期模板)时,MaaFW 可对 ROI 内进行一次额外的 template_negative(负面模板)的匹配,得到高于阈值的若干负面模板匹配区域 $R_j$

对于每个 $R_i$,找到所有 $R_j$ 满足 $R_j ∩ R_i \ne ∅$,如果其中任意 $R_j$ 的匹配分数 $C_j$ 大于 $R_i$ 的匹配分数 $C_i$,则认为 $R_i$ 识别是无效的,应排除。

MaaFramework 版本 / Version

v5.11.1

其他信息 / Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions