fix: clamp face score to 0.00-0.99 and format with 2 decimal places

This commit is contained in:
tian 2026-07-27 19:30:26 +08:00
parent 85e91f3c2f
commit 148fe97a27
2 changed files with 6 additions and 2 deletions

View File

@ -5,6 +5,7 @@
#include <cctype>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <sstream>
#include <string>
#include <string_view>
@ -111,7 +112,7 @@ void HttpAction::Execute(AlarmEvent& event, std::shared_ptr<Frame> /*frame*/) {
const auto& det = event.detections[i];
if (i > 0) oss << ",";
oss << "{\"cls_id\":" << det.cls_id
<< ",\"score\":" << det.score
<< ",\"score\":" << std::fixed << std::setprecision(2) << det.score
<< ",\"bbox\":{\"x\":" << det.bbox.x
<< ",\"y\":" << det.bbox.y
<< ",\"w\":" << det.bbox.w

View File

@ -952,7 +952,10 @@ private:
Detection d;
d.cls_id = -1;
// Unknown: show stranger likelihood (1 - best_sim). Known: show match confidence (best_sim).
d.score = (rule.kind == FaceRule::Kind::Unknown) ? (1.0f - it.best_sim) : it.best_sim;
float rawScore = (rule.kind == FaceRule::Kind::Unknown) ? (1.0f - it.best_sim) : it.best_sim;
if (rawScore < 0.0f) rawScore = 0.0f;
if (rawScore > 0.99f) rawScore = 0.99f;
d.score = rawScore;
d.bbox = it.bbox;
d.track_id = it.person_track_id >= 0 ? it.person_track_id : it.best_person_id;
dets.push_back(std::move(d));