C/C++ YAML配置文件读取

在这里插入图片描述
不能嵌套结构体 mmp
会报错

typedef struct _VideoWrapper{
public:
    std::string video; //mp4
    bool active;
    int chn;
    std::vector<int> times;
    std::vector<cv::Rect> rois;
}VideoWrapper;

typedef struct _VideoStaticWrapper{
    char filetype[8]; //mp4
    char fourcc[8]; //fourcc(h264);
    int width;
    int height;
    float framerate;//输出的帧率
    std::vector<int> active;
    // std::vector<VideoWrapper> videos;
}VideoStaticWrapper;



namespace YAML {
    template<> 
    struct convert<VideoStaticWrapper> {
        static Node encode(const VideoStaticWrapper &rhs) {
            Node node;
            node.push_back(rhs.filetype);
            node.push_back(rhs.fourcc);
            node.push_back(rhs.width);
            node.push_back(rhs.height);
            node.push_back(rhs.framerate);
            node.push_back(rhs.active);
            // node.push_back(rhs.videos);
            return node;
        }

        static bool decode(const Node &node, VideoStaticWrapper &rhs) {
            // memset(&rhs,0,sizeof(VideoStaticWrapper));
            strcpy(rhs.filetype,node["filetype"].as<std::string>().c_str());
            strcpy(rhs.fourcc,node["fourcc"].as<std::string>().c_str());
            rhs.width = node["width"].as<int>();
            rhs.height = node["height"].as<int>();
            rhs.framerate = node["framerate"].as<float>();
            for(auto &i:node["active"]){
                rhs.active.push_back(i.as<int>());
            }
            // for(auto &i:node["videos"]){
            //     bool active = false;
            //     for(auto &j:rhs.active){
            //         if(i["chn"].as<int>()==j){active = true;}
            //     }
            //     std::cout<<i["chn"].as<int>()<<" is "<<active<<std::endl;
            //     VideoWrapper videowrapper;
            //     videowrapper.video = i["video"].as<std::string>();
            //     videowrapper.active = active;
            //     videowrapper.chn = i["chn"].as<int>();
            //     for(auto &ii:i["times"]){
            //         videowrapper.times.push_back(ii.as<int>());
            //     }
            //     for(auto &ii:i["rois"]){
            //         int a,b,c,d;
            //         sscanf(ii.as<std::string>().c_str(),"%d,%d,%d,%d",&a,&b,&c,&d);
            //         cv::Rect rect(a,b,c,d);
            //         videowrapper.rois.push_back(rect);
            //     }
            //     rhs.videos.push_back(videowrapper);
            // }
            // Node nareas = node["areas"];
        }
    };
}

这么玩也不行 第二个vector会报错 无法理解

typedef struct _VideoWrapper{
public:
    std::string video; //mp4
    int chn;
    std::vector<std::string> times;
    std::vector<std::string> rois;
}VideoWrapper;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值