improve pose

This commit is contained in:
2026-05-14 19:17:09 +10:00
parent 8e4d9a9e5d
commit 52ec13a8e3
3 changed files with 98 additions and 2 deletions
+48
View File
@@ -6,6 +6,43 @@
#include <algorithm>
#include <cmath>
namespace {
// ── IoU dedup for end-to-end YOLO person detector output ──────────────
//
// Ultralytics E2E ONNX exports bake NMS into the graph, but its IoU
// threshold is set at export time (default ≈ 0.7) and we can't override
// it from outside. For a top-down pose pipeline that's too lax — pairs
// of overlapping bboxes survive and we end up running RTMPose twice on
// the same person.
//
// This filter walks the detector's output (already sorted by confidence
// in the E2E format), keeping each box only if its IoU with every
// already-kept box is below kPersonDedupIoU. O(N²) is fine because N is
// capped at 300 and typically <10 in practice.
constexpr float kPersonDedupIoU = 0.45f;
inline float boxIoU(const cv::Rect& a, const cv::Rect& b) {
const cv::Rect inter = a & b;
if (inter.area() <= 0) return 0.f;
const int uni = a.area() + b.area() - inter.area();
return uni > 0 ? static_cast<float>(inter.area()) / static_cast<float>(uni) : 0.f;
}
std::vector<ANSCENTER::Object> dedupByIoU(
const std::vector<ANSCENTER::Object>& persons, float iouThr) {
std::vector<ANSCENTER::Object> kept;
kept.reserve(persons.size());
for (const auto& p : persons) {
bool isDup = false;
for (const auto& k : kept) {
if (boxIoU(p.box, k.box) > iouThr) { isDup = true; break; }
}
if (!isDup) kept.push_back(p);
}
return kept;
}
} // anonymous namespace
namespace ANSCENTER {
// ====================================================================
@@ -411,6 +448,17 @@ namespace ANSCENTER {
return {};
}
// IoU dedup — Ultralytics E2E NMS in person.onnx is too lax
// (training-time IoU≈0.7 default), letting near-duplicate
// boxes through. Drop duplicates BEFORE running pose so we
// don't pay for two RTMPose inferences on the same subject.
const size_t beforeDedup = persons.size();
persons = dedupByIoU(persons, kPersonDedupIoU);
if (persons.size() != beforeDedup) {
ANS_DBG("ANSRTRTMPOSE", "RunInference: dedup %zu -> %zu (IoU>%g) cam='%s'",
beforeDedup, persons.size(), kPersonDedupIoU, camera_id.c_str());
}
std::vector<Object> results;
results.reserve(persons.size());
for (const auto& person : persons) {