2026-04-16 21:43:44 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
#include <deque>
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
#include <opencv2/core.hpp>
|
|
|
|
|
|
|
|
|
|
namespace odin_ros_driver {
|
|
|
|
|
|
|
|
|
|
using ReIDFeature = std::vector<float>;
|
|
|
|
|
|
|
|
|
|
struct ReIDTensorRTConfig {
|
|
|
|
|
std::string engine_path;
|
|
|
|
|
int input_height = 256;
|
|
|
|
|
int input_width = 128;
|
|
|
|
|
int feature_dim = 512;
|
|
|
|
|
int max_batch_size = 8;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class TrackGallery {
|
|
|
|
|
public:
|
|
|
|
|
explicit TrackGallery(size_t max_features = 10);
|
|
|
|
|
|
|
|
|
|
void clear();
|
2026-04-20 11:12:02 +08:00
|
|
|
void add(
|
|
|
|
|
const ReIDFeature& feature,
|
|
|
|
|
int64_t frame_index,
|
|
|
|
|
const cv::Mat& crop_bgr = cv::Mat());
|
2026-04-16 21:43:44 +08:00
|
|
|
|
|
|
|
|
bool empty() const { return features_.empty(); }
|
|
|
|
|
size_t size() const { return features_.size(); }
|
|
|
|
|
int64_t last_update_frame() const { return last_update_frame_; }
|
2026-04-20 11:12:02 +08:00
|
|
|
const std::deque<cv::Mat>& crops_bgr() const { return crops_bgr_; }
|
2026-04-16 21:43:44 +08:00
|
|
|
|
|
|
|
|
float best_similarity(const ReIDFeature& query) const;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
std::deque<ReIDFeature> features_;
|
2026-04-20 11:12:02 +08:00
|
|
|
std::deque<cv::Mat> crops_bgr_;
|
2026-04-16 21:43:44 +08:00
|
|
|
size_t max_features_ = 10;
|
|
|
|
|
int64_t last_update_frame_ = -1;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ReIDTensorRTExtractor {
|
|
|
|
|
public:
|
|
|
|
|
ReIDTensorRTExtractor();
|
|
|
|
|
~ReIDTensorRTExtractor();
|
|
|
|
|
|
|
|
|
|
ReIDTensorRTExtractor(const ReIDTensorRTExtractor&) = delete;
|
|
|
|
|
ReIDTensorRTExtractor& operator=(const ReIDTensorRTExtractor&) = delete;
|
|
|
|
|
|
|
|
|
|
void initialize(const ReIDTensorRTConfig& config);
|
|
|
|
|
bool initialized() const { return initialized_; }
|
|
|
|
|
int feature_dim() const;
|
|
|
|
|
|
|
|
|
|
std::vector<ReIDFeature> extract(
|
|
|
|
|
const cv::Mat& frame_bgr,
|
|
|
|
|
const std::vector<cv::Rect>& boxes) const;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
struct Impl;
|
|
|
|
|
std::unique_ptr<Impl> impl_;
|
|
|
|
|
ReIDTensorRTConfig config_;
|
|
|
|
|
bool initialized_ = false;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace odin_ros_driver
|