From ce2a18b6f6a8677c2dd0eef7b13b5ffb233eba63 Mon Sep 17 00:00:00 2001 From: tian <11429339@qq.com> Date: Sun, 15 Mar 2026 20:39:54 +0800 Subject: [PATCH] Filter oversized shoe boxes in dynamic ROI --- configs/person_shoe_two_stage_workshoe_alarm.json | 1 + .../person_shoe_two_stage_workshoe_alarm_v8s_shoe640.json | 1 + ..._shoe_two_stage_workshoe_alarm_v8s_shoe640_strict.json | 1 + plugins/ai_shoe_det/README.md | 1 + plugins/ai_shoe_det/ai_shoe_det_node.cpp | 8 ++++++++ 5 files changed, 12 insertions(+) diff --git a/configs/person_shoe_two_stage_workshoe_alarm.json b/configs/person_shoe_two_stage_workshoe_alarm.json index 5ef2c3a..baededd 100644 --- a/configs/person_shoe_two_stage_workshoe_alarm.json +++ b/configs/person_shoe_two_stage_workshoe_alarm.json @@ -109,6 +109,7 @@ "debug_roi_class_id": -1, "max_rois": 3, "min_person_height": 60, + "max_box_area_ratio": 0.60, "x_offset": -0.24, "y_offset": 0.64, "width_scale": 1.48, diff --git a/configs/person_shoe_two_stage_workshoe_alarm_v8s_shoe640.json b/configs/person_shoe_two_stage_workshoe_alarm_v8s_shoe640.json index b0cbdb7..e8ea068 100644 --- a/configs/person_shoe_two_stage_workshoe_alarm_v8s_shoe640.json +++ b/configs/person_shoe_two_stage_workshoe_alarm_v8s_shoe640.json @@ -109,6 +109,7 @@ "debug_roi_class_id": -1, "max_rois": 3, "min_person_height": 60, + "max_box_area_ratio": 0.60, "x_offset": -0.24, "y_offset": 0.64, "width_scale": 1.48, diff --git a/configs/person_shoe_two_stage_workshoe_alarm_v8s_shoe640_strict.json b/configs/person_shoe_two_stage_workshoe_alarm_v8s_shoe640_strict.json index f415a39..2a27396 100644 --- a/configs/person_shoe_two_stage_workshoe_alarm_v8s_shoe640_strict.json +++ b/configs/person_shoe_two_stage_workshoe_alarm_v8s_shoe640_strict.json @@ -109,6 +109,7 @@ "debug_roi_class_id": -1, "max_rois": 3, "min_person_height": 60, + "max_box_area_ratio": 0.60, "x_offset": -0.24, "y_offset": 0.64, "width_scale": 1.48, diff --git a/plugins/ai_shoe_det/README.md b/plugins/ai_shoe_det/README.md index 60ef4c8..5c97e02 100644 --- a/plugins/ai_shoe_det/README.md +++ b/plugins/ai_shoe_det/README.md @@ -94,6 +94,7 @@ | `shoe_class_id` | 0 | 追加到结果中的鞋类别 ID | | `max_rois` | 8 | 每帧最多处理多少个人 | | `min_person_height` | 0 | 忽略过小的人框,减少无效 ROI | +| `max_box_area_ratio` | 0.0 | 鞋框相对脚部 ROI 的最大面积占比,超过则过滤 | | `x_offset` | -0.15 | ROI 左上角相对人框左上角的横向偏移系数 | | `y_offset` | 0.72 | ROI 左上角相对人框左上角的纵向偏移系数 | | `width_scale` | 1.30 | ROI 宽度相对人框宽度的放大系数 | diff --git a/plugins/ai_shoe_det/ai_shoe_det_node.cpp b/plugins/ai_shoe_det/ai_shoe_det_node.cpp index 8541afc..6d65462 100644 --- a/plugins/ai_shoe_det/ai_shoe_det_node.cpp +++ b/plugins/ai_shoe_det/ai_shoe_det_node.cpp @@ -43,6 +43,7 @@ struct DynamicRoiConfig { int debug_roi_class_id = -1; int max_rois = 8; int min_person_height = 0; + float max_box_area_ratio = 0.0f; float x_offset = -0.15f; float y_offset = 0.72f; float width_scale = 1.30f; @@ -334,6 +335,8 @@ public: dynamic_roi_.max_rois = std::max(1, dyn->ValueOr("max_rois", dynamic_roi_.max_rois)); dynamic_roi_.min_person_height = std::max(0, dyn->ValueOr("min_person_height", dynamic_roi_.min_person_height)); + dynamic_roi_.max_box_area_ratio = + std::max(0.0f, dyn->ValueOr("max_box_area_ratio", dynamic_roi_.max_box_area_ratio)); dynamic_roi_.x_offset = dyn->ValueOr("x_offset", dynamic_roi_.x_offset); dynamic_roi_.y_offset = dyn->ValueOr("y_offset", dynamic_roi_.y_offset); dynamic_roi_.width_scale = dyn->ValueOr("width_scale", dynamic_roi_.width_scale); @@ -664,6 +667,11 @@ private: if (!std::isfinite(x) || !std::isfinite(y) || !std::isfinite(w) || !std::isfinite(h)) return; if (w <= 1e-3f || h <= 1e-3f) return; if (w > model_w_ * 1.2f || h > model_h_ * 1.2f) return; + if (dynamic_roi_.enable && dynamic_roi_.max_box_area_ratio > 0.0f && win_w > 0 && win_h > 0) { + const float mapped_area_ratio = + (w * h) / (static_cast(model_w_) * static_cast(model_h_)); + if (mapped_area_ratio > dynamic_roi_.max_box_area_ratio) return; + } DetBox box; box.x = win_x + x * scale_x;