- 创建基本项目结构和目录 - 添加CMake构建系统 - 实现基础的配置解析功能 - 添加YOLO推理框架支持 - 集成RTSP和视频流处理功能 - 添加性能监控和日志系统
74 lines
2.2 KiB
C++
74 lines
2.2 KiB
C++
#pragma once
|
||
|
||
#include <memory>
|
||
#include <vector>
|
||
#include <opencv2/core.hpp>
|
||
#include "cuda_helper.hpp"
|
||
#include "../common/logger.hpp"
|
||
|
||
namespace pipeline {
|
||
|
||
/**
|
||
* @brief 图像预处理器
|
||
*
|
||
* 负责将输入图像预处理为模型所需的格式:
|
||
* 1. 图像缩放到指定尺寸
|
||
* 2. BGR转RGB
|
||
* 3. 归一化 (0-255 -> 0-1)
|
||
* 4. 批处理支持
|
||
*/
|
||
class Preprocessor {
|
||
public:
|
||
struct Config {
|
||
std::vector<int> input_shape; // [channels, height, width]
|
||
bool use_cuda{true}; // 是否使用CUDA加速
|
||
int max_batch_size{4}; // 最大批处理大小
|
||
float scale{1.0f/255.0f}; // 归一化系数
|
||
};
|
||
|
||
/**
|
||
* @brief 构造函数
|
||
* @param config 预处理配置
|
||
*/
|
||
explicit Preprocessor(const Config& config);
|
||
~Preprocessor();
|
||
|
||
// 禁用拷贝
|
||
Preprocessor(const Preprocessor&) = delete;
|
||
Preprocessor& operator=(const Preprocessor&) = delete;
|
||
|
||
/**
|
||
* @brief 批量预处理图像
|
||
* @param images 输入图像列表
|
||
* @param output_buffer 输出缓冲区(CUDA设备内存)
|
||
* @return 是否成功
|
||
*/
|
||
bool process(const std::vector<cv::Mat>& images, detail::CudaBuffer& output_buffer);
|
||
|
||
/**
|
||
* @brief 获取配置
|
||
* @return 当前配置
|
||
*/
|
||
const Config& getConfig() const { return config_; }
|
||
|
||
private:
|
||
// CPU预处理实现
|
||
bool processCPU(const std::vector<cv::Mat>& images, detail::CudaBuffer& output_buffer);
|
||
|
||
// CUDA预处理实现
|
||
bool processGPU(const std::vector<cv::Mat>& images, detail::CudaBuffer& output_buffer);
|
||
|
||
// 单张图像预处理(CPU版本)
|
||
bool preprocessImageCPU(const cv::Mat& input, float* output, int target_height, int target_width);
|
||
|
||
// 检查输入有效性
|
||
bool checkInput(const std::vector<cv::Mat>& images) const;
|
||
|
||
private:
|
||
Config config_; // 配置参数
|
||
std::unique_ptr<detail::CudaStream> stream_; // CUDA流
|
||
std::vector<std::unique_ptr<detail::CudaBuffer>> temp_buffers_; // 临时缓冲区
|
||
};
|
||
|
||
} // namespace pipeline
|