leon 1 month ago
parent
commit
149660bfb6
1 changed files with 9 additions and 5 deletions
  1. 9 5
      src/nodes/track/trackNode.cpp

+ 9 - 5
src/nodes/track/trackNode.cpp

@@ -26,18 +26,22 @@ void TrackNode::work()
                 continue;
             }
             std::vector<Object> objects;
-            std::transform(metaData->boxes.begin(), metaData->boxes.end(), std::back_inserter(objects), [this](data::Box& box) {
-                if (box.label == track_label_) {
+            for (const auto& box : metaData->boxes) 
+            {
+                if (box.label == track_label_) { // 只处理需要的 label
                     Object obj;
                     obj.rect.x = box.left;
                     obj.rect.y = box.top;
                     obj.rect.width = box.right - box.left;
                     obj.rect.height = box.bottom - box.top;
-                    obj.label = box.class_id;
+                    obj.label = box.class_id; // 假设 Object::label 存的是 int 类型的 class_id
                     obj.prob = box.score;
-                    return obj;
+                    
+                    if (obj.rect.width > 0 && obj.rect.height > 0 && obj.prob > 0) { // 至少prob > 0
+                         objects.push_back(obj); // 只添加有效的对象
+                    }
                 }
-            });
+            }
             // ***** 关键调试打印:检查输入给 tracker 的 objects *****
             printf("节点 %s: tracker_->update() 的输入 objects (共 %zu 个):\n", name_.c_str(), objects.size());
             for (size_t i = 0; i < objects.size(); ++i) {