PCLPointCloud2和PointCloud<T>记录

简介

  • PCLPointCloud2 :以连续内存形式存储,非常适合序列化传输
    ros中有关点云的消息类型是PCLPointCloud2的,这是一个更为通用的数据结构,能够存储各种类型的点云数据,不仅限于 XYZ 或 XYZRGB 等常见的格式。并且可以选择要在其中存储哪些字段,例如仅 XYZ、XYZ + 法线、XYZ + 颜色等。当然灵活的代价就是非常不直观,得搞清楚传来的点云到底是什么。
  • PointCloud:如果指定了类型,会有一些更高效和方便的操作,比如直接对某一字段进行访问。
    缺点就是无法选择存储或者删除某一字段。

二者之间的转换非常方便,pcl中提供了相应的接口

template <typename PointT> 
void fromPCLPointCloud2 (const pcl::PCLPointCloud2& msg, pcl::PointCloud<PointT>& cloud);

template <typename PointT> 
void toPCLPointCloud2 (const pcl::PointCloud<PointT>& cloud, pcl::PCLPointCloud2& msg);

用途

目前有关PCLPointCloud2,除了经常用在ros中以外,最常见的一个用途是用来查询传入的点云是否包含某个字段,比如下面这段pcl示例代码中的一部分:

pcl::PCLPointCloud2 input_pointcloud2;
if (pcl::io::loadPCDFile(pcd_filename, input_pointcloud2))
{
    PCL_ERROR("ERROR: Could not read input point cloud %s.\n", pcd_filename.c_str());
    return (3);
}
pcl::fromPCLPointCloud2(input_pointcloud2, *input_cloud_ptr);
if (!ignore_provided_normals)
{
    if (pcl::getFieldIndex(input_pointcloud2, "normal_x") >= 0)
    {
        pcl::fromPCLPointCloud2(input_pointcloud2, *input_normals_ptr);
        has_normals = true;

        //NOTE Supposedly there was a bug in old PCL versions that the orientation was not set correctly when recording clouds. This is just a workaround.
        if (input_normals_ptr->sensor_orientation_.w() == 0)
        {
            input_normals_ptr->sensor_orientation_.w() = 1;
            input_normals_ptr->sensor_orientation_.x() = 0;
            input_normals_ptr->sensor_orientation_.y() = 0;
            input_normals_ptr->sensor_orientation_.z() = 0;
        }
    }
    else
        PCL_WARN("Could not find normals in pcd file. Normals will be calculated. This only works for single-camera-view pointclouds.\n");
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

糊烟乱雨

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值