fix: restrict face track association to persons
This commit is contained in:
parent
d8d1fb9331
commit
83a07290b1
@ -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": {
|
||||
|
||||
@ -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<Detection>& 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<Detectio
|
||||
int best_track_id = -1;
|
||||
float best_overlap = -1.0f;
|
||||
for (const auto& det : dets) {
|
||||
if (!IsPersonDetection(det)) continue;
|
||||
if (det.track_id < 0) continue;
|
||||
if (!ContainsPoint(det.bbox, center_x, center_y)) continue;
|
||||
|
||||
|
||||
@ -10,15 +10,19 @@
|
||||
namespace rk3588 {
|
||||
namespace {
|
||||
|
||||
Detection MakePersonDetection(int track_id, float x, float y, float w, float h) {
|
||||
Detection MakeDetection(int cls_id, int track_id, float x, float y, float w, float h) {
|
||||
Detection det;
|
||||
det.cls_id = 0;
|
||||
det.cls_id = cls_id;
|
||||
det.track_id = track_id;
|
||||
det.score = 0.95f;
|
||||
det.bbox = Rect{x, y, w, h};
|
||||
return det;
|
||||
}
|
||||
|
||||
Detection MakePersonDetection(int track_id, float x, float y, float w, float h) {
|
||||
return MakeDetection(0, track_id, x, y, w, h);
|
||||
}
|
||||
|
||||
TEST(FaceTrackAssociationTest, PicksContainingTrackedPerson) {
|
||||
const Rect face{50.0f, 50.0f, 20.0f, 20.0f};
|
||||
const std::vector<Detection> 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<Detection> 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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user