pcl::PointCloud<pcl::PointXYZ> 到 pcl::PointCloud<pcl::PointXYZ>::Ltr(将点云转换为 ptr)

pcl::PointCloud<pcl::PointXYZ> to pcl::PointCloud<pcl::PointXYZ>::Ptr (Covert poincloud to ptr)

我正在使用 PCL 1.3。是否有将点云转换为 pointcloud::ptr 的函数?我是 PCL 图书馆的新人。我有一个订阅 sensor_msgs/PoinCloud2 主题的 ROS 节点,然后我将其转换为 pcl::Poincloud,现在我想做 pcl::StatisticalOutlierRemoval。离群值去除函数接受的是指针,而不是 Poincloud 本身(这是我的理解)。因此,为此我想知道如何在它们之间进行转换的解决方案?

pcl::PointCloud<pcl::PointXYZ> point_cloud
pcl::fromPCLPointCloud2(cloud_filtered, point_cloud);


pcl::removeNaNFromPointCloud(point_cloud, point_cloud, nan_idx);

pcl::StatisticalOutlierRemoval<pcl::PointXYZ> sor;
sor.setInputCloud (point_cloud);
sor.setMeanK (50);
sor.setStddevMulThresh (1.0);
sor.filter (*point_cloud);

错误:没有匹配函数 调用'pcl::StatisticalOutlierRemovalpcl::PointXYZ::setInputCloud(**pcl::PointCloudpcl::PointXYZ**&)'

注意:候选人: void pcl::PCLBase::setInputCloud(const PointCloudConstPtr&) [with PointT = pcl::PointXYZ; pcl::PCLBase::PointCloudConstPtr = boost::shared_ptr]

pcl::PointCloud<pcl::PointXYZ>::Ptr 是一个 shared_ptr - 所以,简单地说,它是一个 pointer 的包装器,它管理它的生命周期(在我们的例子中是一个包装器围绕指向 pcl::PointCloud<pcl::PointXYZ>).

的指针

您可以通过传递一个指针来实例化它,例如来自 new 的指针: pcl::PointCloud<pcl::PointXYZ>::Ptr point_cloud(new pcl::PointCloud< pcl::PointXYZ>);

由于 pcl::fromPCLPointCloud2 需要 pcl::PointCloud<pcl::PointXYZ>,您需要 dereferencingpcl::fromPCLPointCloud2(cloud_filtered, *point_cloud);

还值得注意的是,使用 ros_pcl 您可以直接拥有一个订阅者 直接订阅:

const pcl::PointCloud<pcl::PointXYZ>::ConstPtr& message

当 sensor_msgs::PointCloud2 条消息在订阅的主题上发布时,这将开箱即用,您无需调用:

pcl::fromPCLPointCloud2(cloud_filtered, point_cloud);