diff --git a/plugins/logic_gate/color_analyzer.cpp b/plugins/logic_gate/color_analyzer.cpp index 7eb2b5c..affbacd 100644 --- a/plugins/logic_gate/color_analyzer.cpp +++ b/plugins/logic_gate/color_analyzer.cpp @@ -68,10 +68,15 @@ ColorResult ColorAnalyzer::Analyze(const Frame& frame, const Rect& bbox) { result = AnalyzeBrightness(center.data(), inner_w, inner_h, 3); break; default: - result = AnalyzeHSV(center.data(), inner_w, inner_h, 3); + LogWarn("[ColorAnalyzer] Unsupported color method: " + + std::to_string(static_cast(config_.method))); break; } - + + if (!result.valid) { + return result; + } + // 判断是否为劳保鞋颜色 result.is_dark = IsSafetyBootsColor(result); @@ -184,6 +189,7 @@ ColorResult ColorAnalyzer::AnalyzeHSV(const uint8_t* data, int w, int h, int cha result.dark_ratio = dark_pixels / static_cast(total_pixels); result.light_ratio = 1.0f - result.dark_ratio; result.confidence = result.dark_ratio; + result.valid = true; return result; } @@ -213,6 +219,7 @@ ColorResult ColorAnalyzer::AnalyzeRGB(const uint8_t* data, int w, int h, int cha result.dark_ratio = dark_pixels / static_cast(total_pixels); result.light_ratio = 1.0f - result.dark_ratio; result.confidence = result.dark_ratio; + result.valid = true; return result; } diff --git a/plugins/logic_gate/color_analyzer.h b/plugins/logic_gate/color_analyzer.h index 8cd65f5..4eb7d71 100644 --- a/plugins/logic_gate/color_analyzer.h +++ b/plugins/logic_gate/color_analyzer.h @@ -24,6 +24,7 @@ struct ColorConfig { // 颜色分析结果 struct ColorResult { + bool valid = false; // 分析结果是否有效 bool is_dark = false; // 是否为深色 float brightness = 0.0f; // 平均亮度(0-255) float confidence = 0.0f; // 置信度 diff --git a/plugins/logic_gate/logic_gate_node.cpp b/plugins/logic_gate/logic_gate_node.cpp index f85d283..eae2b7a 100644 --- a/plugins/logic_gate/logic_gate_node.cpp +++ b/plugins/logic_gate/logic_gate_node.cpp @@ -200,6 +200,11 @@ private: if (method == "hsv") config.color.method = ColorMethod::HSV; else if (method == "rgb") config.color.method = ColorMethod::RGB; else if (method == "brightness") config.color.method = ColorMethod::BRIGHTNESS; + else { + LogWarn("[logic_gate] unsupported color_check.method=" + method + + ", disabling color analysis"); + config.enable_color_check = false; + } config.color.dark_threshold = color->ValueOr("dark_threshold", 80); config.color.roi_expand = color->ValueOr("roi_expand", 1.0f); config.color.center_w_scale = color->ValueOr("center_w_scale", 0.6f); @@ -384,12 +389,21 @@ private: " match_score=" + std::to_string(match_score)); } if (!pass_gate) continue; + if (config_.person_shoe.enable_size_preferred && !size_preferred) { + if (config_.debug) { + LogInfo("[logic_gate] skip non_preferred shoe person_track=" + + std::to_string(person.track_id) + + " det_idx=" + std::to_string(static_cast(shoe_indices[si])) + + " bbox=(" + std::to_string(static_cast(shoe.bbox.x)) + "," + + std::to_string(static_cast(shoe.bbox.y)) + "," + + std::to_string(static_cast(shoe.bbox.w)) + "," + + std::to_string(static_cast(shoe.bbox.h)) + ")"); + } + continue; + } ++candidate_count; - const bool should_replace = - best_shoe_local < 0 || - (size_preferred && !best_size_preferred) || - (size_preferred == best_size_preferred && match_score > best_match_score); + const bool should_replace = best_shoe_local < 0 || match_score > best_match_score; if (should_replace) { best_shoe_local = static_cast(si); best_match_score = match_score; @@ -479,6 +493,13 @@ private: const Rect mapped_bbox = MapDetCoordToFrame(boot.bbox, frame); const auto color_result = color_analyzer_->Analyze(*frame, mapped_bbox); + if (!color_result.valid) { + if (config_.debug) { + LogInfo("[logic_gate] skip invalid color result track_id=" + + std::to_string(boot.track_id)); + } + continue; + } if (color_result.is_dark) continue; Detection no_boots_det;