feat(resolution): 支持动态分辨率适配#294
Open
Rememorio wants to merge 2 commits into
Open
Conversation
Contributor
Reviewer's Guide围绕 1280x720 基线添加通用的分辨率与画面缩放工具,并将其集成到常用操作与图像匹配工具中,使钓鱼、煮咖啡、家具属性选择、取款物品选择、节奏歌单选择以及 PinkPaw 鼠标操作在 16:9 高分辨率下可用,并在非 16:9 分辨率下具备兜底行为;同时相应更新启动日志。 match_template_in_region_720 兜底匹配的时序图sequenceDiagram
participant Caller
participant Utils as Common.utils
participant Screen as screen
Caller->>Utils: match_template_in_region_720(img, region, template,...)
Utils->>Screen: update_frame_size_from_image(img)
Utils->>Screen: map_rect_to_frame_candidates(region)
Screen-->>Utils: candidates: tuple[RectMapping]
loop for each candidate
Utils->>Utils: resize_template(template, candidate.scale_x, candidate.scale_y,...)
Utils->>Utils: match_template_in_region(img, candidate.rect, scaled_template,..., scale_template=False)
Utils-->>Utils: hit, score, x, y
Utils->>Utils: update best result if score higher
end
Utils-->>Caller: best_hit, best_score, best_x, best_y
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your Experience打开你的 dashboard 以:
Getting HelpOriginal review guide in EnglishReviewer's GuideAdd a generalized resolution and frame scaling utility around a 1280x720 baseline, then integrate it into common actions and image-matching utilities so fishing, coffee-making, furniture selection, withdrawals, rhythm song selection, and PinkPaw mouse actions work under 16:9 high resolutions and have fallback behavior for non-16:9; also update startup logging accordingly. Sequence diagram for match_template_in_region_720 fallback matchingsequenceDiagram
participant Caller
participant Utils as Common.utils
participant Screen as screen
Caller->>Utils: match_template_in_region_720(img, region, template,...)
Utils->>Screen: update_frame_size_from_image(img)
Utils->>Screen: map_rect_to_frame_candidates(region)
Screen-->>Utils: candidates: tuple[RectMapping]
loop for each candidate
Utils->>Utils: resize_template(template, candidate.scale_x, candidate.scale_y,...)
Utils->>Utils: match_template_in_region(img, candidate.rect, scaled_template,..., scale_template=False)
Utils-->>Utils: hit, score, x, y
Utils->>Utils: update best result if score higher
end
Utils-->>Caller: best_hit, best_score, best_x, best_y
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - 我在这里给了一些整体性的反馈:
- 在
match_template_in_region_720中,即使缩放因子重复,模板在每个候选上都会被重新缩放;可以考虑在循环内部按(scale_x, scale_y)缓存已缩放的模板,以避免在热点路径上进行重复的cv2.resize调用。 - 新增的
screen.map_rect_to_frame_candidates(尤其是edge_height/edge_width分支)引入了多个“魔法常量”(比如 0.35/0.65 的中心阈值);把这些常量收集到带名称的常量中,或者简要说明这些取值的依据,可以让映射行为更易于维护和调优。 - 新增的点击/滑动辅助函数现在同时支持原始坐标和 720 基线坐标;你可能需要在对外的辅助函数上通过断言或文档说明预期的坐标空间(例如
click_rectvsclick_rect_720,swipevsswipe_720),以避免未来调用方误用。
供 AI Agent 使用的提示
Please address the comments from this code review:
## Overall Comments
- In `match_template_in_region_720`, the template is resized on every candidate even when scale factors repeat; consider caching resized templates per `(scale_x, scale_y)` within the loop to avoid redundant `cv2.resize` calls on hot paths.
- The new `screen.map_rect_to_frame_candidates` (especially the `edge_height`/`edge_width` branches) introduces several magic constants (like the 0.35/0.65 center thresholds); collecting these into named constants or briefly explaining the rationale would make the mapping behavior easier to maintain and tune.
- The new click/swipe helpers now support both raw and 720-baseline coordinates; you might want to assert or document expected coordinate space on the public helpers (e.g., `click_rect` vs `click_rect_720`, `swipe` vs `swipe_720`) to avoid accidental misuse in future call sites.帮我变得更有用!请在每条评论上点击 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English
Hey - I've left some high level feedback:
- In
match_template_in_region_720, the template is resized on every candidate even when scale factors repeat; consider caching resized templates per(scale_x, scale_y)within the loop to avoid redundantcv2.resizecalls on hot paths. - The new
screen.map_rect_to_frame_candidates(especially theedge_height/edge_widthbranches) introduces several magic constants (like the 0.35/0.65 center thresholds); collecting these into named constants or briefly explaining the rationale would make the mapping behavior easier to maintain and tune. - The new click/swipe helpers now support both raw and 720-baseline coordinates; you might want to assert or document expected coordinate space on the public helpers (e.g.,
click_rectvsclick_rect_720,swipevsswipe_720) to avoid accidental misuse in future call sites.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `match_template_in_region_720`, the template is resized on every candidate even when scale factors repeat; consider caching resized templates per `(scale_x, scale_y)` within the loop to avoid redundant `cv2.resize` calls on hot paths.
- The new `screen.map_rect_to_frame_candidates` (especially the `edge_height`/`edge_width` branches) introduces several magic constants (like the 0.35/0.65 center thresholds); collecting these into named constants or briefly explaining the rationale would make the mapping behavior easier to maintain and tune.
- The new click/swipe helpers now support both raw and 720-baseline coordinates; you might want to assert or document expected coordinate space on the public helpers (e.g., `click_rect` vs `click_rect_720`, `swipe` vs `swipe_720`) to avoid accidental misuse in future call sites.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Collaborator
|
加下开发群谢谢喵1092630280 |
Author
|
已处理 Sourcery 的三点建议:
补充验证:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
关联 Issue
需求来源:本地排查发现 MaaNTE 对
1280x720依赖较强,需要支持异环在 16:9 高分辨率窗口/全屏下运行,并为非 16:9 场景提供更稳的识别兜底。无关联 Issue。变更摘要
match_template_in_region_720,可在非 16:9 下尝试 stretch / fit / fill / edge-aware 等候选模型并取最高分。验证
python -m compileall -q agent通过。git diff --check通过。Win32 DPI-aware 实机读取
HTGame.execlient size:1920x1080,scale(1.5, 1.5),16:9 判定通过。使用真实
1920x1080异环登录画面截图验证齿轮模板匹配:720p 模板自动缩放后命中[1847, 24],score0.9622。合成
1440x900非 16:9 帧验证 stretch / fit / edge_height 三类候选映射均可命中,score 均为1.0。我已阅读并遵守 PR 规范
截图 / 日志 / 说明
HTGame.exe,Windows 显示缩放 150% 下 DPI-aware 读取到真实1920x1080client size。SetWindowPos自动切换更多尺寸;非 16:9 通过合成帧覆盖 stretch / fit / edge-aware 映射模型。Summary by Sourcery
添加分辨率感知的屏幕工具,并迁移交互和模板匹配逻辑,以支持从 1280x720 基线到任意窗口和画面尺寸(包括非 16:9 纵横比)的动态缩放。
新功能:
增强内容:
Original summary in English
Summary by Sourcery
Add a resolution-aware screen utility and migrate interaction and template matching logic to support dynamic scaling from a 1280x720 baseline to arbitrary window and frame sizes, including non-16:9 aspect ratios.
New Features:
Enhancements: