Correct logic in RTMPOSE when using generic model to detect person

This commit is contained in:
2026-05-14 19:33:31 +10:00
parent 52ec13a8e3
commit 71404affb7
3 changed files with 43 additions and 13 deletions
+21 -4
View File
@@ -720,13 +720,31 @@ namespace ANSCENTER {
// --- Top-down path ---
if (personDetector) {
std::vector<Object> persons = personDetector->RunInference(inputImage, camera_id);
if (persons.empty()) {
ANS_DBG("ANSONNXRTMPOSE", "DetectObjects: detector found 0 persons cam='%s'",
std::vector<Object> detections = personDetector->RunInference(inputImage, camera_id);
if (detections.empty()) {
ANS_DBG("ANSONNXRTMPOSE", "DetectObjects: detector found 0 detections cam='%s'",
camera_id.c_str());
return {};
}
// person.onnx may be a multi-class detector (e.g. a generic
// COCO YOLO with 80 classes). The COCO 'person' class is id=0
// by convention. Drop everything else BEFORE pose / dedup so
// we don't waste cycles on cars, dogs, signs, etc.
std::vector<Object> persons;
persons.reserve(detections.size());
for (auto& d : detections) {
if (d.classId != 0) continue;
if (d.box.width <= 0 || d.box.height <= 0) continue;
persons.push_back(std::move(d));
}
if (persons.empty()) {
ANS_DBG("ANSONNXRTMPOSE",
"DetectObjects: %zu detections but 0 persons (classId==0) cam='%s'",
detections.size(), camera_id.c_str());
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
@@ -741,7 +759,6 @@ namespace ANSCENTER {
std::vector<Object> out;
out.reserve(persons.size());
for (const auto& person : persons) {
if (person.box.width <= 0 || person.box.height <= 0) continue;
Object pose = engine->estimate(inputImage, person.box);
if (pose.kps.empty()) continue;
pose.cameraId = camera_id;
+21 -8
View File
@@ -441,13 +441,31 @@ namespace ANSCENTER {
// overload which crops each bbox and routes per-crop
// through our Preprocess.
if (m_personDetector) {
std::vector<Object> persons = m_personDetector->RunInference(inputImgBGR, camera_id);
if (persons.empty()) {
ANS_DBG("ANSRTRTMPOSE", "RunInference: detector found 0 persons cam='%s'",
std::vector<Object> detections = m_personDetector->RunInference(inputImgBGR, camera_id);
if (detections.empty()) {
ANS_DBG("ANSRTRTMPOSE", "RunInference: detector found 0 detections cam='%s'",
camera_id.c_str());
return {};
}
// person.onnx may be a multi-class detector (e.g. a generic
// COCO YOLO with 80 classes). The COCO 'person' class is id=0
// by convention. Drop everything else BEFORE pose / dedup so
// we don't waste cycles on cars, dogs, signs, etc.
std::vector<Object> persons;
persons.reserve(detections.size());
for (auto& d : detections) {
if (d.classId != 0) continue;
if (d.box.width <= 0 || d.box.height <= 0) continue;
persons.push_back(std::move(d));
}
if (persons.empty()) {
ANS_DBG("ANSRTRTMPOSE",
"RunInference: %zu detections but 0 persons (classId==0) cam='%s'",
detections.size(), camera_id.c_str());
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
@@ -462,11 +480,6 @@ namespace ANSCENTER {
std::vector<Object> results;
results.reserve(persons.size());
for (const auto& person : persons) {
// person.onnx is a single-class model — accept anything
// the detector returned, but defend against degenerate
// boxes (zero/negative area, off-image).
if (person.box.width <= 0 || person.box.height <= 0) continue;
auto poseResults = InferenceOnBox(inputImgBGR, person.box, camera_id);
for (auto& obj : poseResults) {
// Carry the detector's track-id and confidence so