Skip to content

refactor: Go模板匹配优化函数分离到minicv包#1010

Merged
isHarryh merged 3 commits intoMaaEnd:mainfrom
isHarryh:main
Mar 5, 2026
Merged

refactor: Go模板匹配优化函数分离到minicv包#1010
isHarryh merged 3 commits intoMaaEnd:mainfrom
isHarryh:main

Conversation

@isHarryh
Copy link
Member

@isHarryh isHarryh commented Mar 5, 2026

概要

此 PR 分离了 Go Agent 的归一化互相关系数计算函数和两个模板匹配函数到 minicv 包。

Summary by Sourcery

将 Go 模板匹配和归一化互相关(NCC)逻辑从 map-tracker 中抽取出来,迁移到共享的 minicv 包中,并更新 map-tracker 以使用新的 API。

增强内容:

  • 在 minicv 包中引入可复用的 NCC 计算和模板匹配辅助方法,包括区域限制匹配和基于积分图的统计工具。
  • 调整 map-tracker 的推理代码,使其调用新的 minicv 模板匹配函数,而不是本地实现。
  • 通过对极小方差进行钳制(clamp),提升 minicv 统计工具中方差计算的数值稳定性。
Original summary in English

Summary by Sourcery

Extract Go template matching and normalized cross-correlation logic from the map-tracker into the shared minicv package and update map-tracker to use the new APIs.

Enhancements:

  • Introduce reusable NCC computation and template matching helpers in the minicv package, including area-restricted matching and integral-based stats utilities.
  • Adjust map-tracker inference code to call the new minicv template matching functions instead of local implementations.
  • Improve numerical stability of variance calculations in minicv stats utilities by clamping very small variances.

Copilot AI review requested due to automatic review settings March 5, 2026 08:36
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - 我在这里提供了一些整体性的反馈:

  • match_template.go 中,循环 for y := range thfor range twfor i := range numWorkersfor range numWorkers 试图对整数进行 range 操作,代码将无法编译;这些循环应该改写为常规的索引循环(例如 for y := 0; y < th; y++for i := 0; i < numWorkers; i++ 以及相应的计数循环)。
  • GetImageStats(以及 GetAreaStats)中,用于将标准差归零的方差阈值从 1e-3 改成了 1e-6;请考虑这个更严格的阈值是否会在无意中增加被视为有效的低方差区域数量,并与之前的实现相比改变匹配行为。
给 AI 代理的提示
Please address the comments from this code review:

## Overall Comments
- In `match_template.go` the loops `for y := range th`, `for range tw`, `for i := range numWorkers`, and `for range numWorkers` attempt to range over integers and will not compile; these should be rewritten as conventional index loops (e.g., `for y := 0; y < th; y++`, `for i := 0; i < numWorkers; i++`, and corresponding counted loops).
- The variance threshold used to zero out the standard deviation was changed from `1e-3` to `1e-6` in `GetImageStats` (and `GetAreaStats`); consider whether this tighter threshold might unintentionally increase the number of low-variance regions treated as valid and alter matching behavior compared to the previous implementation.

Sourcery 对开源项目是免费的——如果你觉得我们的代码评审有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的代码评审。
Original comment in English

Hey - I've left some high level feedback:

  • In match_template.go the loops for y := range th, for range tw, for i := range numWorkers, and for range numWorkers attempt to range over integers and will not compile; these should be rewritten as conventional index loops (e.g., for y := 0; y < th; y++, for i := 0; i < numWorkers; i++, and corresponding counted loops).
  • The variance threshold used to zero out the standard deviation was changed from 1e-3 to 1e-6 in GetImageStats (and GetAreaStats); consider whether this tighter threshold might unintentionally increase the number of low-variance regions treated as valid and alter matching behavior compared to the previous implementation.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `match_template.go` the loops `for y := range th`, `for range tw`, `for i := range numWorkers`, and `for range numWorkers` attempt to range over integers and will not compile; these should be rewritten as conventional index loops (e.g., `for y := 0; y < th; y++`, `for i := 0; i < numWorkers; i++`, and corresponding counted loops).
- The variance threshold used to zero out the standard deviation was changed from `1e-3` to `1e-6` in `GetImageStats` (and `GetAreaStats`); consider whether this tighter threshold might unintentionally increase the number of low-variance regions treated as valid and alter matching behavior compared to the previous implementation.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the Go Agent’s template-matching implementation by moving normalized cross-correlation (NCC) and template-matching helpers out of map-tracker into the shared pkg/minicv package, and updating map tracking inference to use the new minicv APIs.

Changes:

  • Add minicv.ComputeNCC, minicv.MatchTemplate, and minicv.MatchTemplateInArea as reusable template-matching utilities.
  • Extend minicv.IntegralArray with GetAreaStats to compute mean/std for sub-rectangles efficiently.
  • Remove duplicated template-matching logic from map-tracker and switch infer.go call sites to the new minicv functions.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
agent/go-service/pkg/minicv/stats_utils.go Adjust variance clamping logic and add IntegralArray.GetAreaStats for area mean/std.
agent/go-service/pkg/minicv/match_template.go Introduce shared NCC + template matching (full-image and bounded-area) utilities.
agent/go-service/map-tracker/utils.go Remove map-tracker-local template matching helpers now provided by minicv.
agent/go-service/map-tracker/infer.go Update inference flow to call minicv.MatchTemplate* functions.
Comments suppressed due to low confidence (1)

agent/go-service/pkg/minicv/match_template.go:2

  • New file is missing the repository’s standard copyright header comment seen at the top of other agent/go-service Go files. Add the same header for consistency.
package minicv

@isHarryh
Copy link
Member Author

isHarryh commented Mar 5, 2026

此 PR 未影响现有逻辑表现,属于可兼容的、非破坏性变更,将立即合并。

@isHarryh isHarryh merged commit 2733707 into MaaEnd:main Mar 5, 2026
16 checks passed
MistEO pushed a commit that referenced this pull request Mar 9, 2026
## 概要

此 PR 分离了 Go Agent 的归一化互相关系数计算函数和两个模板匹配函数到 minicv 包。

## Summary by Sourcery

将 Go 模板匹配和归一化互相关(NCC)逻辑从 map-tracker 中抽取出来,迁移到共享的 minicv 包中,并更新
map-tracker 以使用新的 API。

增强内容:
- 在 minicv 包中引入可复用的 NCC 计算和模板匹配辅助方法,包括区域限制匹配和基于积分图的统计工具。
- 调整 map-tracker 的推理代码,使其调用新的 minicv 模板匹配函数,而不是本地实现。
- 通过对极小方差进行钳制(clamp),提升 minicv 统计工具中方差计算的数值稳定性。

<details>
<summary>Original summary in English</summary>

## Summary by Sourcery

Extract Go template matching and normalized cross-correlation logic from
the map-tracker into the shared minicv package and update map-tracker to
use the new APIs.

Enhancements:
- Introduce reusable NCC computation and template matching helpers in
the minicv package, including area-restricted matching and
integral-based stats utilities.
- Adjust map-tracker inference code to call the new minicv template
matching functions instead of local implementations.
- Improve numerical stability of variance calculations in minicv stats
utilities by clamping very small variances.

</details>
MistEO pushed a commit that referenced this pull request Mar 9, 2026
## 概要

此 PR 分离了 Go Agent 的归一化互相关系数计算函数和两个模板匹配函数到 minicv 包。

## Summary by Sourcery

将 Go 模板匹配和归一化互相关(NCC)逻辑从 map-tracker 中抽取出来,迁移到共享的 minicv 包中,并更新
map-tracker 以使用新的 API。

增强内容:
- 在 minicv 包中引入可复用的 NCC 计算和模板匹配辅助方法,包括区域限制匹配和基于积分图的统计工具。
- 调整 map-tracker 的推理代码,使其调用新的 minicv 模板匹配函数,而不是本地实现。
- 通过对极小方差进行钳制(clamp),提升 minicv 统计工具中方差计算的数值稳定性。

<details>
<summary>Original summary in English</summary>

## Summary by Sourcery

Extract Go template matching and normalized cross-correlation logic from
the map-tracker into the shared minicv package and update map-tracker to
use the new APIs.

Enhancements:
- Introduce reusable NCC computation and template matching helpers in
the minicv package, including area-restricted matching and
integral-based stats utilities.
- Adjust map-tracker inference code to call the new minicv template
matching functions instead of local implementations.
- Improve numerical stability of variance calculations in minicv stats
utilities by clamping very small variances.

</details>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants