代码之家  ›  专栏  ›  技术社区  ›  eirikaso

使用YAML cpp错误分析YAML文件

  •  1
  • eirikaso  · 技术社区  · 7 年前

    我正在尝试解析来自的信息。将带有摄像头校准的yaml文件放入ROS中的“sensor\u msgs::Cameranfo”消息中。

    我设法同时解析int和string,但在使用双向量/矩阵时遇到了问题。

    这是我的代码:

    sensor_msgs::CameraInfo yamlToCameraInfo(std::string leftOrRightCam)
    {
      YAML::Node camera_info_yaml = YAML::LoadFile(leftOrRightCam + ".yaml");
      sensor_msgs::CameraInfo camera_info_msg;
      camera_info_msg.width = camera_info_yaml["image_width"].as<uint32_t>();
      camera_info_msg.height = camera_info_yaml["image_height"].as<uint32_t>();
      camera_info_msg.distortion_model = camera_info_yaml["distortion_model"].as<std::string>();
      camera_info_msg.D = camera_info_yaml["distortion_coefficients"].as<double>();
      camera_info_msg.K = camera_info_yaml["camera_matrix"].as<double>();
    
      return camera_info_msg;
    
    }
    

    我得到的错误是:

    错误:“operator=”不匹配(操作数类型为 '传感器\u msgs::CameraInfo\ugt;::_D\U类型{aka std::矢量(>}'和“双倍”)
    camera\u info\u消息。D= 摄像头信息yaml[“失真系数”]。as();

    Cameranfo消息的文档位于此处: http://docs.ros.org/api/sensor_msgs/html/msg/CameraInfo.html

    yaml cpp包教程: https://github.com/jbeder/yaml-cpp/wiki/Tutorial

    yaml文件lokk中的“畸变系数”部分如下所示:

    畸变系数:
    行:1
    cols:5
    数据:[-0.167477,0.023595,0.004069,-0.002996,0.000000]

    有人知道我做错了什么吗?

    1 回复  |  直到 7 年前
        1
  •  1
  •   Jesse Beder    7 年前

    此行错误:

    camera_info_msg.D = camera_info_yaml["distortion_coefficients"].as<double>();
    

    表明左侧是 std::vector<double> 而右侧是 double .相反:

    camera_info_msg.D = camera_info_yaml["distortion_coefficients"].as<std::vector<double>>();