123456789101112131415161718192021222324252627282930313233343536373839 |
- #include "nodes/track/trackNode.hpp"
- namespace GNode
- {
- void TrackNode::handle_data(std::shared_ptr<meta::MetaData>& meta_data)
- {
- if (!track_map_[meta_data->from] )
- {
- track_map_[meta_data->from] = std::make_shared<BYTETracker>(frame_rate_, track_buffer_);
- }
- std::vector<Object> 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<STrack> output_stracks = track_map_[input_buffer.first] ->update(objects);
- for (const auto& track : output_stracks) {
- const std::vector<float>& 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
|