diff --git a/modules/ANSODEngine/ANSONNXRTMPOSE.cpp b/modules/ANSODEngine/ANSONNXRTMPOSE.cpp index ae4ab88..6fc9a5a 100644 --- a/modules/ANSODEngine/ANSONNXRTMPOSE.cpp +++ b/modules/ANSODEngine/ANSONNXRTMPOSE.cpp @@ -720,13 +720,31 @@ namespace ANSCENTER { // --- Top-down path --- if (personDetector) { - std::vector persons = personDetector->RunInference(inputImage, camera_id); - if (persons.empty()) { - ANS_DBG("ANSONNXRTMPOSE", "DetectObjects: detector found 0 persons cam='%s'", + std::vector 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 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 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; diff --git a/modules/ANSODEngine/ANSRTRTMPOSE.cpp b/modules/ANSODEngine/ANSRTRTMPOSE.cpp index 1bf28d4..1d03817 100644 --- a/modules/ANSODEngine/ANSRTRTMPOSE.cpp +++ b/modules/ANSODEngine/ANSRTRTMPOSE.cpp @@ -441,13 +441,31 @@ namespace ANSCENTER { // overload which crops each bbox and routes per-crop // through our Preprocess. if (m_personDetector) { - std::vector persons = m_personDetector->RunInference(inputImgBGR, camera_id); - if (persons.empty()) { - ANS_DBG("ANSRTRTMPOSE", "RunInference: detector found 0 persons cam='%s'", + std::vector 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 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 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 diff --git a/tests/ANSODEngine-UnitTest/ANSODEngine-UnitTest.cpp b/tests/ANSODEngine-UnitTest/ANSODEngine-UnitTest.cpp index ea0b817..eae0eab 100644 --- a/tests/ANSODEngine-UnitTest/ANSODEngine-UnitTest.cpp +++ b/tests/ANSODEngine-UnitTest/ANSODEngine-UnitTest.cpp @@ -1999,7 +1999,7 @@ int FallDetectorTest() { int RTMPOSETest() { int modelType = 32; // ONNX YOLO (30) RT YOLO (31) std::string onnxclmodelFilePath = "E:\\Programs\\DemoAssets\\ANSAIModels\\PoseEstimationModels\\ANSRTMPOSE.zip"; - std::string videoFile = "E:\\Programs\\DemoAssets\\Videos\\rtmpose.mp4";//"E:\\Programs\\DemoAssets\\Videos\\train.mp4"; + std::string videoFile = "E:\\Programs\\DemoAssets\\Videos\\ANSOffice.mp4";//"E:\\Programs\\DemoAssets\\Videos\\rtmpose.mp4";// VideoDetectorEngine(onnxclmodelFilePath, videoFile, modelType);// 22 is RT, 21 is onnx return 0; }