2025-12-31 16:30:10 +08:00
|
|
|
|
#pragma once
|
2025-12-24 16:14:25 +08:00
|
|
|
|
|
|
|
|
|
|
#include <atomic>
|
2026-01-04 15:47:02 +08:00
|
|
|
|
#include <memory> // [新增] 用于 unique_ptr
|
2025-12-31 16:30:10 +08:00
|
|
|
|
#include <opencv2/opencv.hpp>
|
2025-12-24 16:14:25 +08:00
|
|
|
|
#include <string>
|
|
|
|
|
|
#include <thread>
|
2025-12-31 16:30:10 +08:00
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
|
|
#include "spdlog/spdlog.h"
|
2026-01-04 15:47:02 +08:00
|
|
|
|
#include "yoloDetector/yolo_detector.hpp" // [新增] 包含检测器头文件 (同时也包含了 DetectionResult 定义)
|
2025-12-31 16:30:10 +08:00
|
|
|
|
|
2026-01-04 15:47:02 +08:00
|
|
|
|
// [删除] 移除此处定义的 DetectionResult,直接使用 yolo_detector.hpp 中的定义
|
|
|
|
|
|
/*
|
2025-12-31 16:30:10 +08:00
|
|
|
|
struct DetectionResult {
|
|
|
|
|
|
int x;
|
|
|
|
|
|
int y;
|
|
|
|
|
|
int width;
|
|
|
|
|
|
int height;
|
|
|
|
|
|
std::string label;
|
|
|
|
|
|
float confidence;
|
|
|
|
|
|
};
|
2026-01-04 15:47:02 +08:00
|
|
|
|
*/
|
2025-12-24 16:14:25 +08:00
|
|
|
|
|
|
|
|
|
|
class VideoPipeline {
|
|
|
|
|
|
public:
|
|
|
|
|
|
VideoPipeline();
|
|
|
|
|
|
~VideoPipeline();
|
|
|
|
|
|
|
2025-12-31 16:30:10 +08:00
|
|
|
|
// 启动视频流处理
|
2025-12-24 16:14:25 +08:00
|
|
|
|
void Start(const std::string& inputUrl, const std::string& outputUrl);
|
2026-01-04 14:52:14 +08:00
|
|
|
|
void StartTest(const std::string& filePath, const std::string& outputUrl);
|
2025-12-24 16:14:25 +08:00
|
|
|
|
|
2025-12-31 16:30:10 +08:00
|
|
|
|
// 停止处理
|
2025-12-24 16:14:25 +08:00
|
|
|
|
void Stop();
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
2026-01-04 14:52:14 +08:00
|
|
|
|
void processLoop(std::string inputUrl, std::string outputUrl, bool isFileSource);
|
2025-12-24 16:14:25 +08:00
|
|
|
|
|
2026-01-04 15:47:02 +08:00
|
|
|
|
// [删除] 移除模拟推理函数
|
|
|
|
|
|
// std::vector<DetectionResult> mockInference(const cv::Mat& frame);
|
2025-12-24 16:14:25 +08:00
|
|
|
|
|
2025-12-31 16:30:10 +08:00
|
|
|
|
// 绘图函数
|
|
|
|
|
|
void drawOverlay(cv::Mat& frame, const std::vector<DetectionResult>& results);
|
2025-12-24 16:14:25 +08:00
|
|
|
|
|
2026-01-04 15:47:02 +08:00
|
|
|
|
private:
|
2025-12-31 16:30:10 +08:00
|
|
|
|
std::atomic<bool> running_;
|
|
|
|
|
|
std::thread processingThread_;
|
2026-01-04 15:47:02 +08:00
|
|
|
|
|
|
|
|
|
|
// [新增] YOLO 检测器实例
|
|
|
|
|
|
std::unique_ptr<YoloDetector> detector_;
|
2025-12-24 16:14:25 +08:00
|
|
|
|
};
|