Correct logic in RTMPOSE when using generic model to detect person
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user