pcl::concatenatePointCloud函数使用与报错

1. 记录一个小问题,凑够200篇,hhh

 报错

error: invalid initialization of reference of type ‘const pcl::PCLPointCloud2&’ from expression of type ‘pcl::PointCloud<pcl::PointXYZ>’

 源代码如下

    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_in(new pcl::PointCloud<pcl::PointXYZ>);
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_out(new pcl::PointCloud<pcl::PointXYZ>);    
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_final(new pcl::PointCloud<pcl::PointXYZ>);
    pcl::concatenatePointCloud(*cloud_in, *output_cloud, *cloud_final);

原因与解决:

这个错误是因为pcl::concatenatePointCloud函数的第一个和第二个参数类型应该是const pcl::PCLPointCloud2&,而传递的是pcl::PointCloud<pcl::PointXYZ>类型的指针。可以使用以下代码将点云转换为pcl::PCLPointCloud2类型:

// 添加
pcl::PCLPointCloud2::Ptr cloud_in_blob(new pcl::PCLPointCloud2);
pcl::PCLPointCloud2::Ptr output_cloud_blob(new pcl::PCLPointCloud2);
pcl::PCLPointCloud2::Ptr cloud_final_blob(new pcl::PCLPointCloud2);

pcl::toPCLPointCloud2(*cloud_in, *cloud_in_blob);
pcl::toPCLPointCloud2(*output_cloud, *output_cloud_blob);


pcl::concatenatePointCloud(*cloud_in_blob, *output_cloud_blob, *cloud_final_blob);//修改位置

pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_final(new pcl::PointCloud<pcl::PointXYZ>);
pcl::fromPCLPointCloud2(*cloud_final_blob, *cloud_final);

这个代码将pcl::PointCloud<pcl::PointXYZ>类型的点云转换为pcl::PCLPointCloud2类型,将它们进行拼接,然后再将结果转换回pcl::PointCloud<pcl::PointXYZ>类型。

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
pcl::concatenatePointCloudPCL(点云库)中的一个函数,用于将多个点云数据合并成一个点云。 具体来说,concatenatePointCloud 函数可以将多个 pcl::PointCloud 对象连接起来,形成一个包含所有点的大点云。 函数的声明如下: ```cpp template<typename PointT> void concatenatePointCloud(const pcl::PointCloud<PointT> &cloud1, const pcl::PointCloud<PointT> &cloud2, pcl::PointCloud<PointT> &output); ``` 这个函数模板有一个类型参数 PointT,表示点的类型,可以是 pcl::PointXYZ、pcl::PointXYZRGB 等等。 使用 concatenatePointCloud 函数时,需要传入两个输入点云对象 cloud1 和 cloud2,并提供一个输出点云对象 output 来接收合并后的点云数据。 示例代码如下: ```cpp pcl::PointCloud<pcl::PointXYZ>::Ptr cloud1(new pcl::PointCloud<pcl::PointXYZ>); pcl::PointCloud<pcl::PointXYZ>::Ptr cloud2(new pcl::PointCloud<pcl::PointXYZ>); // 假设 cloud1 和 cloud2 已经被填充了点云数据 pcl::PointCloud<pcl::PointXYZ>::Ptr concatenatedCloud(new pcl::PointCloud<pcl::PointXYZ>); pcl::concatenatePointCloud(*cloud1, *cloud2, *concatenatedCloud); ``` 在这个示例中,首先创建了两个 pcl::PointCloud<pcl::PointXYZ> 指针对象 cloud1 和 cloud2,并假设它们分别已经被填充了点云数据。 然后,创建了一个新的 pcl::PointCloud<pcl::PointXYZ> 指针对象 concatenatedCloud,用于存储合并后的点云数据。 接下来,调用 concatenatePointCloud 函数cloud1 和 cloud2 合并为 concatenatedCloud,合并后的点云数据将存储在 concatenatedCloud 指向的对象中。 注意,由于 concatenatePointCloud 函数的参数是引用类型,所以需要使用 *cloud1、*cloud2 和 *concatenatedCloud 来获取它们所指向的实际对象。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值