#pragma once #include #include // [新增] #include #include #include #include #include #include "spdlog/spdlog.h" #include "yoloDetector/yolo_detector.hpp" // [新增] 定义追踪车辆的结构体 struct TrackedVehicle { int id; // 唯一ID cv::Rect box; // 当前位置 float ev_score; // 新能源分数 (0.0 - 1.0), 越接近1.0越可能是新能源 int missing_frames; // 连续丢失帧数 (用于删除消失的车辆) int last_class_id; // 上一次显示的类别ID (避免标签闪烁) std::string label; // 当前显示的标签 }; class VideoPipeline { public: VideoPipeline(); ~VideoPipeline(); void Start(const std::string& inputUrl, const std::string& outputUrl); void StartTest(const std::string& filePath, const std::string& outputUrl); void Stop(); private: void processLoop(std::string inputUrl, std::string outputUrl, bool isFileSource); // [修改] 绘图函数现在接收追踪列表,而不是原始检测结果 void drawOverlay(cv::Mat& frame, const std::vector& trackedObjects); // [新增] 核心:更新追踪和分数逻辑 void updateTracker(const std::vector& detections); // [新增] 辅助函数:计算 IoU (交并比) float computeIOU(const cv::Rect& box1, const cv::Rect& box2); private: std::atomic running_; std::thread processingThread_; std::unique_ptr detector_; // [新增] 追踪列表,Key是ID std::map tracks_; int next_track_id_ = 0; };