Feat/outpost filter#50
Conversation
|
Caution Review failedPull request was closed or merged during review Walkthrough该 PR 新增绿灯检测与定位模块,更新 Identifier 返回契约以按 OUTPOST/BASE 绿灯底边过滤装甲,补充绘制与文本工具,在 runtime 可视化绿灯与 ATTACK/IDLE 状态,并调整配置与追踪过滤规则。 Changes绿灯装甲识别与过滤
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
config/config.yaml (1)
54-59: ⚡ Quick win建议为绿灯过滤增加显式开关位。
outpost_green_light_filter目前只有阈值参数,建议增加enabled布尔开关,方便赛场快速回滚/AB 对比,避免只能通过改阈值“间接关闭”功能。建议改动
outpost_green_light_filter: + enabled: true green_threshold: 120 min_area: 20 min_circularity: 0.6 max_aspect_ratio: 1.5🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@config/config.yaml` around lines 54 - 59, Add an explicit boolean switch "enabled" to the outpost_green_light_filter config (e.g., outpost_green_light_filter.enabled: true) so the feature can be toggled without changing thresholds (green_threshold, min_area, min_circularity, max_aspect_ratio); then update all code paths that apply the green-light filter to first check this flag (where the filter is referenced/used) and skip filtering when enabled is false. Ensure the default is true to preserve current behavior and include validation/typing in the config loader so missing values fall back to the default.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/module/identifier/green_light_armor_filter.cpp`:
- Around line 22-31: The early returns in filter (function filter) skip updating
the detector state, so green_light() can yield stale rectangles across frames;
call a clear method on the detector at start of filter (add and use
GreenLightDetection::clear() on green_light_detection) before any early-return
paths (i.e., before checking armors.empty() and before compute_detect_roi early
return), and also ensure clear() is invoked when
green_light_detection.sync_detect(...) returns no value so the detector state is
reset consistently instead of preserving last-frame results.
In `@src/runtime.cpp`:
- Line 215: 当前在绘制文本的调用 util::draw_text(*image, command.should_shoot ? "ATTACK" :
"IDLE"); 未受 use_painted_image 开关约束导致即使关闭叠加仍修改图像并增加开销;请将该调用包裹在与其它叠加绘制相同的条件判断中(例如
if (use_painted_image) { util::draw_text(...); }),保持对 command.should_shoot
的现有用法并确保与其它 overlay 绘制代码使用相同的开关变量和位置以避免重复绘制/性能回退。
In `@src/utility/image/green_light.cpp`:
- Around line 11-17: The functions draw_green_light and draw_text are marked
noexcept but call OpenCV functions (cv::rectangle, cv::putText, etc.) that can
throw cv::Exception; remove the noexcept specifier from the draw_green_light
definition in green_light.cpp and from the draw_text definition in text.cpp so
OpenCV exceptions can propagate normally (or alternatively explicitly mark as
noexcept(false) if you prefer), ensuring no noexcept remains on these function
signatures.
---
Nitpick comments:
In `@config/config.yaml`:
- Around line 54-59: Add an explicit boolean switch "enabled" to the
outpost_green_light_filter config (e.g., outpost_green_light_filter.enabled:
true) so the feature can be toggled without changing thresholds
(green_threshold, min_area, min_circularity, max_aspect_ratio); then update all
code paths that apply the green-light filter to first check this flag (where the
filter is referenced/used) and skip filtering when enabled is false. Ensure the
default is true to preserve current behavior and include validation/typing in
the config loader so missing values fall back to the default.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 92fe4d0c-6462-4a5c-9704-ae6492294abe
📒 Files selected for processing (13)
config/config.yamlsrc/kernel/identifier.cppsrc/kernel/identifier.hppsrc/module/identifier/green_light_armor_filter.cppsrc/module/identifier/green_light_armor_filter.hppsrc/module/identifier/green_light_detection.cppsrc/module/identifier/green_light_detection.hppsrc/module/tracker/armor_filter.cppsrc/runtime.cppsrc/utility/image/green_light.cppsrc/utility/image/green_light.hppsrc/utility/image/text.cppsrc/utility/image/text.hpp
| auto draw_green_light(Image& canvas, const cv::Rect2i& rect) noexcept -> void { | ||
| auto& opencv_mat = canvas.details().mat; | ||
|
|
||
| cv::rectangle(opencv_mat, rect, cv::Scalar { 0, 255, 0 }, 2, cv::LINE_AA); | ||
| cv::putText(opencv_mat, "green_light", | ||
| cv::Point2i { rect.x, std::max(rect.y - 6, 0) }, cv::FONT_HERSHEY_SIMPLEX, 0.6, | ||
| cv::Scalar { 0, 255, 0 }, 1, cv::LINE_AA); |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# 只读验证:定位 noexcept 绘制函数与 OpenCV 调用并列出现的位置
rg -nP 'auto\s+draw_(green_light|text)\s*\([^)]*\)\s*noexcept' src/utility/image
rg -nP 'cv::(rectangle|putText|getTextSize)\s*\(' src/utility/imageRepository: Alliance-Algorithm/rmcs_auto_aim_v2
Length of output: 1535
🏁 Script executed:
# 读取 green_light.cpp 和 green_light.hpp 的完整实现
cat -n src/utility/image/green_light.cppRepository: Alliance-Algorithm/rmcs_auto_aim_v2
Length of output: 761
🏁 Script executed:
# 读取 green_light.hpp 的完整实现
cat -n src/utility/image/green_light.hppRepository: Alliance-Algorithm/rmcs_auto_aim_v2
Length of output: 335
🏁 Script executed:
# 读取 text.cpp 以对比实现模式
cat -n src/utility/image/text.cppRepository: Alliance-Algorithm/rmcs_auto_aim_v2
Length of output: 1357
🌐 Web query:
OpenCV cv::rectangle cv::putText throw exception noexcept guarantee
💡 Result:
OpenCV drawing functions such as cv::rectangle and cv::putText do not provide a noexcept guarantee [1][2]. In fact, they are designed to throw exceptions when they encounter errors, such as invalid arguments, incorrect image types, or memory issues [3][4][2]. OpenCV uses the cv::Exception class (which inherits from std::exception) to signal critical errors [2]. These exceptions are typically triggered by internal assertions (e.g., CV_Assert) that validate input parameters, such as image dimensions, data types, or coordinate ranges [3][4][2]. If these conditions are not met, the library throws an exception rather than failing silently or returning an error code [2]. Because these functions can throw, they are not noexcept-compliant. If you are calling them in a context where exceptions must not propagate (such as a destructor or a noexcept function), you must wrap the calls in a try-catch block to handle potential cv::Exception instances [2]. Additionally, while OpenCV aims for efficiency, certain extreme inputs (such as extremely large rectangles) may lead to undefined behavior or crashes if they trigger integer overflows before an assertion can catch them [5]. In some cases, particularly when dealing with external dependencies like FreeType for text rendering, bugs in the underlying libraries can also lead to crashes or segmentation faults rather than standard C++ exceptions [6].
Citations:
- 1: https://docs.opencv.org/4.x/d6/d6e/group__imgproc__draw.html
- 2: https://www.opencv.org.cn/opencvdoc/2.3.1/opencv2refman.pdf
- 3: FreeType/TTF putText crashes with CV_32FC3 (low priority) opencv/opencv_contrib#2771
- 4: error: (-215: Assertion failed) inputs.size() == requiredOutputs in function 'getMemoryShapes' opencv/opencv#16288
- 5: cv::rectangle with very large cv::Rect triggers undefined behavior sanitizer opencv/opencv#21037
- 6: [branch next]: seg. fault in imgproc putText method when a certain TTF font is used opencv/opencv#19224
🏁 Script executed:
# 验证 text.hpp 声明
cat -n src/utility/image/text.hppRepository: Alliance-Algorithm/rmcs_auto_aim_v2
Length of output: 318
🏁 Script executed:
# 检查是否还有其他绘制函数有相同问题
rg -n 'noexcept.*->.*void' src/utility/image/*.cpp | grep -E 'draw_|text'Repository: Alliance-Algorithm/rmcs_auto_aim_v2
Length of output: 300
移除 noexcept,允许 OpenCV 异常正常传播而非导致进程终止。
第 11 行函数声明为 noexcept,但第 14-17 行的 cv::rectangle 和 cv::putText 调用会在参数验证失败时抛出 cv::Exception。异常逸出 noexcept 函数将触发 std::terminate,导致进程强制终止且不可恢复。
建议修复
--- a/src/utility/image/green_light.hpp
+++ b/src/utility/image/green_light.hpp
@@ -6,6 +6,6 @@
namespace rmcs::util {
-auto draw_green_light(Image&, const cv::Rect2i&) noexcept -> void;
+auto draw_green_light(Image&, const cv::Rect2i&) -> void;--- a/src/utility/image/green_light.cpp
+++ b/src/utility/image/green_light.cpp
@@ -8,7 +8,7 @@
namespace rmcs::util {
-auto draw_green_light(Image& canvas, const cv::Rect2i& rect) noexcept -> void {
+auto draw_green_light(Image& canvas, const cv::Rect2i& rect) -> void {
auto& opencv_mat = canvas.details().mat;同样的问题也存在于 src/utility/image/text.cpp 的 draw_text 函数。
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| auto draw_green_light(Image& canvas, const cv::Rect2i& rect) noexcept -> void { | |
| auto& opencv_mat = canvas.details().mat; | |
| cv::rectangle(opencv_mat, rect, cv::Scalar { 0, 255, 0 }, 2, cv::LINE_AA); | |
| cv::putText(opencv_mat, "green_light", | |
| cv::Point2i { rect.x, std::max(rect.y - 6, 0) }, cv::FONT_HERSHEY_SIMPLEX, 0.6, | |
| cv::Scalar { 0, 255, 0 }, 1, cv::LINE_AA); | |
| auto draw_green_light(Image& canvas, const cv::Rect2i& rect) -> void { | |
| auto& opencv_mat = canvas.details().mat; | |
| cv::rectangle(opencv_mat, rect, cv::Scalar { 0, 255, 0 }, 2, cv::LINE_AA); | |
| cv::putText(opencv_mat, "green_light", | |
| cv::Point2i { rect.x, std::max(rect.y - 6, 0) }, cv::FONT_HERSHEY_SIMPLEX, 0.6, | |
| cv::Scalar { 0, 255, 0 }, 1, cv::LINE_AA); |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/utility/image/green_light.cpp` around lines 11 - 17, The functions
draw_green_light and draw_text are marked noexcept but call OpenCV functions
(cv::rectangle, cv::putText, etc.) that can throw cv::Exception; remove the
noexcept specifier from the draw_green_light definition in green_light.cpp and
from the draw_text definition in text.cpp so OpenCV exceptions can propagate
normally (or alternatively explicitly mark as noexcept(false) if you prefer),
ensuring no noexcept remains on these function signatures.
|
现在这版 AI 率有点高,我们还是等赛后慢慢合进去吧 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/kernel/identifier.cpp`:
- Around line 43-50: When a green light is present the code currently applies
the y-position threshold to all entries in detected_armors and may drop
non-OUTPOST targets; change the loop in the block that uses
locator_result.green_light and threshold_y so that you only apply the vertical
filter to armors whose device id equals DeviceId::OUTPOST (e.g., check
armor.device_id == DeviceId::OUTPOST before comparing armor.center.y to
threshold_y) and for all other armors push them into filtered unchanged; keep
the existing behavior when green_light is not present.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 2e074ed1-8b90-47d1-91e1-efdfffe5de46
📒 Files selected for processing (4)
config/config.yamlsrc/kernel/identifier.cppsrc/module/identifier/green_light_locator.cppsrc/module/identifier/green_light_locator.hpp
✅ Files skipped from review due to trivial changes (1)
- config/config.yaml
…armors within green light regions
…hin green light regions
功能: 哨兵绿灯检测与装甲过滤
概述
本 PR 引入基于绿灯检测的装甲过滤机制(对 OUTPOST 与 BASE 两类均生效),在识别流程中定位绿灯并按 Y 坐标阈值剔除与绿灯重叠或位于绿灯上方的装甲,配套新增检测/定位模块与可视化工具,调整若干配置参数与运行时展示逻辑。
核心改动
1. 标识符模块重构
Identifier::sync_identify(const Image&)从std::optional<std::vector<Armor2D>>改为std::optional<Identifier::Result>。Identifier::Result:包含Armor2Ds armors以及可选的outpost_green_light与base_green_light(均为std::optional<cv::Rect2i>)。2. 绿灯检测模块(新增)
GreenLightDetection(实现与初始化),提供接口initialize(const YAML::Node&)与sync_detect(const Image&, const cv::Rect2i&) -> std::optional<cv::Rect2i>。3. 绿灯定位器(新增)
GreenLightLocator,封装对GreenLightDetection的使用并实现自适应 ROI 计算。GreenLightDetection::sync_detect获取绿灯矩形并返回Result { std::optional<cv::Rect2i> green_light }。green_light_filter节点初始化该定位器。4. 可视化与文本绘制(新增)
rmcs::util::draw_green_light(Image&, const cv::Rect2i&)在图像上绘制绿灯矩形与标签(noexcept)。rmcs::util::draw_text(Image&, const std::string&),实现带阴影/描边的文本渲染(用于显示攻击状态)。src/runtime.cpp当使用涂装图像且识别结果有效时,会绘制result->armors并按outpost_green_light/base_green_light的可用性叠加绿灯标识;调用 tracker 之前将使用result->armors;在火控求解后若启用可视化会绘制"ATTACK"或"IDLE"文本。5. 配置与参数调整
green_light_filter配置块(包含 green_threshold、min_area、min_circularity、max_aspect_ratio 等)(注:raw diff 中为
green_light_filter,而非此前摘要中的outpost_green_light_filter)6. 其他小改动
DeviceId::UNKNOWN(之前仅排除INFANTRY_5)。代码审查复杂度
注意事项