Skip to content

feat: wait_freezes draw#1177

Merged
MistEO merged 3 commits intomainfrom
feat/wait_freezes_draw
Mar 4, 2026
Merged

feat: wait_freezes draw#1177
MistEO merged 3 commits intomainfrom
feat/wait_freezes_draw

Conversation

@MistEO
Copy link
Member

@MistEO MistEO commented Mar 4, 2026

Summary by Sourcery

wait_freezes 比较添加调试可视化,并集中管理视觉调试图像的保存。

New Features:

  • wait_freezes 处理过程中,为模板比较结果生成组合调试图像。
  • 引入共享的 VisionBase 工具,用于将编码后的视觉调试图像以带时间戳文件名的方式保存到磁盘。

Enhancements:

  • 通过新的 VisionBase::save_draws 辅助函数来保存 Recognizer 图像,以统一日志记录行为。
  • 将流水线名称向下传递到 wait_freezes 调用中,使保存的调试图像标签更清晰。
Original summary in English

Summary by Sourcery

Add debug visualization for wait_freezes comparisons and centralize saving of vision debug images.

New Features:

  • Generate composite debug images for template comparison results during wait_freezes processing.
  • Introduce a shared VisionBase utility to save encoded vision debug images to disk with timestamped filenames.

Enhancements:

  • Route Recognizer image saving through the new VisionBase::save_draws helper to unify logging behavior.
  • Propagate pipeline names into wait_freezes calls so saved debug images are better labeled.

Copilot AI review requested due to automatic review settings March 4, 2026 09:58
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 - 我发现了 1 个问题,并给出了一些整体性的反馈:

  • ActionHelper::wait_freezes 中,comparator.draws() 在一个左值上调用了一个 && 限定的方法,按当前写法将无法编译;你可能想要的是 VisionBase::save_draws(draw_name, std::move(comparator).draws());
  • VisionBase::save_draws 在循环中对 draws 中的每个元素生成的是相同的文件名,因此后面的图像可能会覆盖前面的图像;建议在格式化的文件名中追加循环索引或每张图像的 ID。
面向 AI Agent 的提示
Please address the comments from this code review:

## Overall Comments
- In `ActionHelper::wait_freezes`, `comparator.draws()` calls an `&&`-qualified method on an lvalue and will not compile as written; you likely want `VisionBase::save_draws(draw_name, std::move(comparator).draws());` instead.
- `VisionBase::save_draws` generates the same filename for every element in `draws` within the loop, so later images may overwrite earlier ones; consider appending the loop index or a per-image ID to the formatted filename.

## Individual Comments

### Comment 1
<location path="source/MaaFramework/Vision/VisionBase.cpp" line_range="90-96" />
<code_context>
+    auto dir = option.log_dir() / "vision";
+    std::filesystem::create_directories(dir);
+
+    for (const auto& draw : draws) {
+        std::string filename = std::format("{}_{}.jpg", format_now_for_filename(), name);
+        auto filepath = dir / std::filesystem::path(filename);
+
+        std::ofstream of(filepath, std::ios::out | std::ios::binary);
+        of.write(reinterpret_cast<const char*>(draw.data()), draw.size());
+        LogDebug << "save draw to" << filepath;
+    }
+}
</code_context>
<issue_to_address>
**issue (bug_risk):** Multiple draws in a single call will all use the same filename and overwrite each other.

Because `filename` is based only on `format_now_for_filename()` and `name`, every iteration in the loop writes to the same `filepath`, so only the final buffer is kept. To prevent silently overwriting earlier draws, either add a per-draw index/unique suffix to the filename or generate a single multi-image artifact instead of one file per draw.
</issue_to_address>

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

Hey - I've found 1 issue, and left some high level feedback:

  • In ActionHelper::wait_freezes, comparator.draws() calls an &&-qualified method on an lvalue and will not compile as written; you likely want VisionBase::save_draws(draw_name, std::move(comparator).draws()); instead.
  • VisionBase::save_draws generates the same filename for every element in draws within the loop, so later images may overwrite earlier ones; consider appending the loop index or a per-image ID to the formatted filename.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `ActionHelper::wait_freezes`, `comparator.draws()` calls an `&&`-qualified method on an lvalue and will not compile as written; you likely want `VisionBase::save_draws(draw_name, std::move(comparator).draws());` instead.
- `VisionBase::save_draws` generates the same filename for every element in `draws` within the loop, so later images may overwrite earlier ones; consider appending the loop index or a per-image ID to the formatted filename.

## Individual Comments

### Comment 1
<location path="source/MaaFramework/Vision/VisionBase.cpp" line_range="90-96" />
<code_context>
+    auto dir = option.log_dir() / "vision";
+    std::filesystem::create_directories(dir);
+
+    for (const auto& draw : draws) {
+        std::string filename = std::format("{}_{}.jpg", format_now_for_filename(), name);
+        auto filepath = dir / std::filesystem::path(filename);
+
+        std::ofstream of(filepath, std::ios::out | std::ios::binary);
+        of.write(reinterpret_cast<const char*>(draw.data()), draw.size());
+        LogDebug << "save draw to" << filepath;
+    }
+}
</code_context>
<issue_to_address>
**issue (bug_risk):** Multiple draws in a single call will all use the same filename and overwrite each other.

Because `filename` is based only on `format_now_for_filename()` and `name`, every iteration in the loop writes to the same `filepath`, so only the final buffer is kept. To prevent silently overwriting earlier draws, either add a per-draw index/unique suffix to the filename or generate a single multi-image artifact instead of one file per draw.
</issue_to_address>

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 adds persistent debug artifacts (“draw” images) for wait_freezes comparisons and centralizes draw-file writing logic in the vision layer so multiple components can reuse it.

Changes:

  • Added VisionBase::save_draws(...) to consolidate draw saving to ${log_dir}/vision.
  • Extended TemplateComparator to generate a combined side-by-side visualization (lhs/rhs + ROI + score) when draw/debug is enabled.
  • Threaded pipeline/node naming into wait_freezes so saved images are attributable to the triggering node/action.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
source/MaaFramework/Vision/VisionBase.h Exposes a reusable static save_draws API.
source/MaaFramework/Vision/VisionBase.cpp Implements centralized draw saving to disk.
source/MaaFramework/Vision/TemplateComparator.h Declares draw_result(...) helper for visualization.
source/MaaFramework/Vision/TemplateComparator.cpp Generates and stores comparator visualization draws.
source/MaaFramework/Task/Component/Recognizer.cpp Refactors to use VisionBase::save_draws instead of local file-writing logic.
source/MaaFramework/Task/Component/Actuator.h Extends wait_freezes signature to accept a name for draw attribution.
source/MaaFramework/Task/Component/Actuator.cpp Passes pipeline node name through to wait_freezes.
source/MaaFramework/Task/Component/ActionHelper.h Extends wait_freezes to accept an optional name.
source/MaaFramework/Task/Component/ActionHelper.cpp Creates/saves wait_freezes comparator draws using the provided name.

MistEO and others added 2 commits March 4, 2026 18:27
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@MistEO MistEO merged commit 716ebcf into main Mar 4, 2026
19 checks passed
@MistEO MistEO deleted the feat/wait_freezes_draw branch March 4, 2026 11:57
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