60 lines
1.7 KiB
C++
60 lines
1.7 KiB
C++
#include <gtest/gtest.h>
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "face/face_recog_debug.h"
|
|
|
|
#include "../plugins/ai_face_recog/ai_face_recog_node.cpp"
|
|
|
|
namespace rk3588 {
|
|
namespace {
|
|
|
|
Detection MakePersonDetection(int track_id, float x, float y, float w, float h) {
|
|
Detection det;
|
|
det.cls_id = 0;
|
|
det.track_id = track_id;
|
|
det.score = 0.95f;
|
|
det.bbox = Rect{x, y, w, h};
|
|
return det;
|
|
}
|
|
|
|
TEST(FaceTrackAssociationTest, PicksContainingTrackedPerson) {
|
|
const Rect face{50.0f, 50.0f, 20.0f, 20.0f};
|
|
const std::vector<Detection> dets = {
|
|
MakePersonDetection(101, 45.0f, 45.0f, 20.0f, 20.0f),
|
|
MakePersonDetection(202, 40.0f, 40.0f, 40.0f, 40.0f),
|
|
MakePersonDetection(303, 10.0f, 10.0f, 15.0f, 15.0f),
|
|
};
|
|
|
|
EXPECT_EQ(AssociateFaceToPersonTrack(face, dets), 202);
|
|
}
|
|
|
|
TEST(FaceTrackAssociationTest, RejectsWhenNoTrackedPersonMatches) {
|
|
const Rect face{50.0f, 50.0f, 20.0f, 20.0f};
|
|
const std::vector<Detection> dets = {
|
|
MakePersonDetection(-1, 45.0f, 45.0f, 20.0f, 20.0f),
|
|
MakePersonDetection(404, 200.0f, 200.0f, 20.0f, 20.0f),
|
|
};
|
|
|
|
EXPECT_EQ(AssociateFaceToPersonTrack(face, dets), -1);
|
|
}
|
|
|
|
TEST(FaceTrackAssociationTest, DebugLineIncludesPersonTrackId) {
|
|
FaceRecogItem item;
|
|
item.person_track_id = 88;
|
|
item.candidate_person_id = 7;
|
|
item.candidate_name = "alice";
|
|
item.best_sim = 0.89f;
|
|
item.second_sim = 0.74f;
|
|
item.unknown = false;
|
|
|
|
const std::string line = BuildFaceRecogDebugSummaryLine("face_recog", 42, item);
|
|
|
|
EXPECT_NE(line.find("person_track_id=88"), std::string::npos);
|
|
EXPECT_NE(line.find("candidate=alice"), std::string::npos);
|
|
}
|
|
|
|
} // namespace
|
|
} // namespace rk3588
|