【问题标题】:Parsing YAML file using yaml-cpp error使用 yaml-cpp 解析 YAML 文件错误
【发布时间】:2018-10-13 11:49:42
【问题描述】:

我正在尝试将带有相机校准的 .yaml 文件中的信息解析为 ROS 中的“sensor_msgs::CameraInfo”消息。

我设法解析了 INT 和字符串,但是当我到达双向量/矩阵时遇到了问题。

这是我的代码:

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=' 不匹配(操作数类型为 'sensor_msgs::CameraInfo_ >::_D_type {aka std::vector >}' 和 'double')
camera_info_msg.D = camera_info_yaml["distortion_coefficients"].as();

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

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

我的 yaml 文件 lokk 的“失真系数”部分如下所示:

失真系数:
行数:1
列:5
数据:[-0.167477, 0.023595, 0.004069, -0.002996, 0.000000]

有谁知道我做错了什么?

【问题讨论】:

  • 这里的distortion_coefficients 节点是一张地图。我猜你需要遍历distortion_coefficients 节点并获取项目

标签: c++ yaml ros yaml-cpp


【解决方案1】:

这一行的错误:

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

建议左侧是std::vector&lt;double&gt;,而右侧是double。而是:

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

【讨论】:

  • 是的。问题确实是 D 是一个向量。我没有让您的特定代码行工作,但我已经使用这个位“ for (std::size_t i=0;i()); }"
猜你喜欢
  • 2020-10-14
  • 1970-01-01
  • 2015-12-06
  • 2015-05-14
  • 2019-06-23
  • 1970-01-01
  • 1970-01-01
  • 2018-10-04
  • 1970-01-01
相关资源
最近更新 更多