#include "nodes/track/trackNode.hpp" namespace GNode { void TrackNode::handle_data(std::shared_ptr& meta_data) { if (!track_map_[meta_data->from] ) { track_map_[meta_data->from] = std::make_shared(frame_rate_, track_buffer_); } std::vector objects; for (const auto& box : meta_data->boxes) { // 只处理需要的 label if (box.label == track_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; // 假设 Object::label 存的是 int 类型的 class_id obj.prob = box.score; if (obj.rect.width > 0 && obj.rect.height > 0 && obj.prob > 0) { // 至少prob > 0 objects.push_back(obj); // 只添加有效的对象 } } } std::vector output_stracks = track_map_[input_buffer.first] ->update(objects); for (const auto& track : output_stracks) { const std::vector& tlwh = track.tlwh; meta_data->track_boxes.emplace_back(tlwh[0], tlwh[1], tlwh[0] + tlwh[2], tlwh[1] + tlwh[3], track.score, track.track_id, track_label_); } }; } // namespace Node