配置文件
width : 640
height : 360
framerate : 25.0
faces_active: [5,6,7,1]
cameras_active: [1,2,3]
channels:
- rtsp: rtsp://admin:a12345678@192.168.1.2:554/Streaming/Channels/102
chn: 1
- rtsp: rtsp://admin:a12345678@192.168.1.2:554/Streaming/Channels/302
chn: 2
- rtsp: rtsp://admin:a12345678@192.168.1.2:554/Streaming/Channels/202
chn: 3
videos:
- path: 25_0.mp4
id: 1
- path: 25_1.mp4
id: 2
templates:
- face: 1
seq:
- video,1,00:00:10,10
- video,2,00:00:10,10
- cemera,-,00:00:00,10
- video,1,00:00:30,10
- cemera,-,00:00:00,10
- video,2,00:00:30,10
声明
YAML::Node config = YAML::LoadFile("setting.yaml");
YAML_Parse_Config yaml_parse;
yaml_parse.width = config["width"].as<int>();
yaml_parse.height = config["height"].as<int>();
yaml_parse.framerate = config["framerate"].as<float>();
yaml_parse.faces_active = config["faces_active"].as<std::vector<int>>();
yaml_parse.cameras_active = config["cameras_active"].as<std::vector<int>>();
yaml_parse.Chns_Config = config["channels"].as<std::vector<Chn_Config>>();
yaml_parse.Videos_Config = config["videos"].as<std::vector<Video_Config>>();
yaml_parse.Templates_Config = config["templates"].as<std::vector<Template_Config>>();
模板
namespace YAML {
template<>
struct convert<Chn_Config> {
static Node encode(const Chn_Config &rhs) {
Node node;
node.push_back(rhs.rtsp);
node.push_back(rhs.chn);
return node;
}
static bool decode(const Node &node, Chn_Config &rhs) {
rhs.rtsp = node["rtsp"].as<std::string>();
rhs.chn = node["chn"].as<int>();
return true;
}
};
template<>
struct convert<Video_Config> {
static Node encode(const Video_Config &rhs) {
Node node;
node.push_back(rhs.path);
node.push_back(rhs.id);
return node;
}
static bool decode(const Node &node, Video_Config &rhs) {
rhs.path = node["path"].as<std::string>();
rhs.id = node["id"].as<int>();
return true;
}
};
template<>
struct convert<Template_Config> {
static Node encode(const Template_Config &rhs) {
Node node;
node.push_back(rhs.face);
node.push_back(rhs.seq);
return node;
}
static bool decode(const Node &node, Template_Config &rhs) {
rhs.face = node["face"].as<int>();
rhs.seq = node["seq"].as<std::vector<std::string>>();
return true;
}
};
}