rtsp_tensorrt/pipeline/common/config_parser.hpp
sladro e13cb3659c feat: 初始化项目结构
- 创建基本项目结构和目录
- 添加CMake构建系统
- 实现基础的配置解析功能
- 添加YOLO推理框架支持
- 集成RTSP和视频流处理功能
- 添加性能监控和日志系统
2024-12-24 16:25:03 +08:00

116 lines
3.2 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#include <memory>
#include <string>
#include <vector>
#include <unordered_map>
#include <map>
#include <opencv2/core/types.hpp>
namespace pipeline {
// 输入源配置
struct InputSourceConfig {
std::string type; // rtsp/video
std::string name; // 输入源名称
std::string url; // RTSP URL
int buffer_size{30}; // 缓冲区大小
std::vector<std::string> outputs; // 输出目标名称列表
};
// 输入配置
struct InputConfig {
std::vector<InputSourceConfig> sources; // 输入源列表
int max_batch_size{4}; // 最大批处理大小
};
// 模型配置
struct ModelConfig {
std::string engine_path; // 模型文件路径
std::vector<int> input_shape{3, 640, 640}; // 输入尺寸
std::string precision{"FP16"}; // 精度模式
struct {
float conf{0.5f}; // 置信度阈值
float nms{0.45f}; // NMS阈值
} threshold;
int gpu_id{0}; // GPU设备ID
};
// 渲染配置
struct RenderConfig {
// 窗口配置
struct {
std::string name{"Detection Results"};
int width{1280};
int height{720};
bool fullscreen{false};
} window;
// 类别样式配置
struct ClassStyle {
cv::Scalar box_color{0, 255, 0}; // BGR格式默认绿色
cv::Scalar text_color{255, 255, 255}; // BGR格式默认白色
float transparency{0.0f}; // 0.0-1.00表示不透明
int box_thickness{2}; // 默认线宽
double font_scale{0.5}; // 默认字体大小
int font_thickness{1}; // 默认字体粗细
};
// 每个类别的样式映射
std::map<std::string, ClassStyle> class_styles;
// 默认样式
ClassStyle default_style;
// 性能指标显示设置
struct {
bool show_fps{true};
bool show_inference_time{true};
bool show_gpu_usage{true};
int update_interval_ms{1000};
} metrics;
};
// 输出目标配置
struct OutputTargetConfig {
std::string type; // video/rtsp
std::string name; // 输出名称
std::string path; // 输出路径
int fps{30}; // 帧率
std::string codec{"h264"}; // 编码器
int bitrate{4000000}; // 比特率
};
// 输出配置
struct OutputConfig {
std::vector<OutputTargetConfig> targets; // 输出目标列表
};
// 日志配置
struct LogConfig {
std::string level{"info"}; // 日志级别
std::string save_path{"logs/"}; // 保存路径
};
// 完整Pipeline配置
struct PipelineConfig {
InputConfig input; // 输入配置
ModelConfig inference; // 推理配置
RenderConfig render; // 渲染配置
OutputConfig output; // 输出配置
LogConfig log; // 日志配置
};
class ConfigParser {
public:
virtual ~ConfigParser() = default;
virtual bool parse(const std::string& config_file) = 0;
virtual bool validate() = 0;
virtual const PipelineConfig& getConfig() const = 0;
};
// 创建配置解析器
std::unique_ptr<ConfigParser> createConfigParser();
} // namespace pipeline