From 83a07290b1aaa5840821cd236392e44184400239 Mon Sep 17 00:00:00 2001 From: tian <11429339@qq.com> Date: Wed, 15 Apr 2026 14:49:30 +0800 Subject: [PATCH] fix: restrict face track association to persons --- configs/full_pipeline_1080p_test_alarm.json | 8 ++++---- plugins/ai_face_recog/ai_face_recog_node.cpp | 7 +++++++ tests/test_face_track_association.cpp | 17 +++++++++++++++-- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/configs/full_pipeline_1080p_test_alarm.json b/configs/full_pipeline_1080p_test_alarm.json index 9f0d32a..f4d832c 100644 --- a/configs/full_pipeline_1080p_test_alarm.json +++ b/configs/full_pipeline_1080p_test_alarm.json @@ -442,10 +442,6 @@ ], [ "face_det", - "face_recog" - ], - [ - "face_recog", "person_det" ], [ @@ -454,6 +450,10 @@ ], [ "person_trk", + "face_recog" + ], + [ + "face_recog", "shoe_det", { "queue": { diff --git a/plugins/ai_face_recog/ai_face_recog_node.cpp b/plugins/ai_face_recog/ai_face_recog_node.cpp index c3eea98..757061b 100644 --- a/plugins/ai_face_recog/ai_face_recog_node.cpp +++ b/plugins/ai_face_recog/ai_face_recog_node.cpp @@ -44,6 +44,8 @@ bool ReadFileToString(const std::string& path, std::string& out) { return ifs.good(); } +constexpr int kPersonClassId = 0; + inline float IntersectionArea(const Rect& a, const Rect& b) { const float left = std::max(a.x, b.x); const float top = std::max(a.y, b.y); @@ -59,6 +61,10 @@ inline bool ContainsPoint(const Rect& r, float x, float y) { return x >= r.x && y >= r.y && x <= (r.x + r.w) && y <= (r.y + r.h); } +inline bool IsPersonDetection(const Detection& det) { + return det.cls_id == kPersonClassId; +} + int AssociateFaceToPersonTrack(const Rect& face_bbox, const std::vector& dets) { const float center_x = face_bbox.x + face_bbox.w * 0.5f; const float center_y = face_bbox.y + face_bbox.h * 0.5f; @@ -66,6 +72,7 @@ int AssociateFaceToPersonTrack(const Rect& face_bbox, const std::vector dets = { @@ -40,6 +44,15 @@ TEST(FaceTrackAssociationTest, RejectsWhenNoTrackedPersonMatches) { EXPECT_EQ(AssociateFaceToPersonTrack(face, dets), -1); } +TEST(FaceTrackAssociationTest, RejectsNonPersonDetections) { + const Rect face{50.0f, 50.0f, 20.0f, 20.0f}; + const std::vector dets = { + MakeDetection(1, 909, 40.0f, 40.0f, 40.0f, 40.0f), + }; + + EXPECT_EQ(AssociateFaceToPersonTrack(face, dets), -1); +} + TEST(FaceTrackAssociationTest, DebugLineIncludesPersonTrackId) { FaceRecogItem item; item.person_track_id = 88;