pcl :: PCLPointCloud2用法

时间:2016-04-03 00:20:20

标签: c++ point-cloud-library

我对何时使用pcl::PointCloud2 vs pcl::PointCloudPointCloud

感到困惑

例如,对pcl1_ptrApcl1_ptrBpcl1_ptrC使用这些定义:

pcl::PointCloud<pcl::PointXYZRGB>::Ptr pcl1_ptrA(new pcl::PointCloud<pcl::PointXYZRGB>); //pointer for color version of pointcloud
pcl::PointCloud<pcl::PointXYZRGB>::Ptr pcl1_ptrB(new pcl::PointCloud<pcl::PointXYZRGB>); //ptr to hold filtered Kinect image
pcl::PointCloud<pcl::PointXYZRGB>::Ptr pcl1_ptrC(new pcl::PointCloud<pcl::PointXYZRGB>); //ptr to hold filtered Kinect image

我可以调用以下PCL函数:

pcl::VoxelGrid<pcl::PointXYZRGB> vox;

vox.setInputCloud(pcl1_ptrA); 

vox.setLeafSize(0.02f, 0.02f, 0.02f);

vox.filter(*pcl1_ptrB); 

cout<<"done voxel filtering"<<endl;

cout<<"num bytes in original cloud data = "<<pcl1_ptrA->points.size()<<endl;

cout<<"num bytes in filtered cloud data = "<<pcl1_ptrB->points.size()<<endl; // ->data.size()<<endl; 

Eigen::Vector4f xyz_centroid; 

pcl::compute3DCentroid (*pcl1_ptrB, xyz_centroid);

float curvature;

Eigen::Vector4f plane_parameters;  

pcl::computePointNormal(*pcl1_ptrB, plane_parameters, curvature); //pcl fnc to compute plane fit to point cloud

Eigen::Affine3f A(Eigen::Affine3f::Identity());

pcl::transformPointCloud(*pcl1_ptrB, *pcl1_ptrC, A);    

但是,如果我改为使用pcl::PCLPointCloud2个对象,例如:

pcl::PCLPointCloud2::Ptr pcl2_ptrA (new pcl::PCLPointCloud2 ());

pcl::PCLPointCloud2::Ptr pcl2_ptrB (new pcl::PCLPointCloud2 ());

pcl::PCLPointCloud2::Ptr pcl2_ptrC (new pcl::PCLPointCloud2 ());

此功能有效:

pcl::VoxelGrid<pcl::PCLPointCloud2> vox;

vox.setInputCloud(pcl2_ptrA); 

vox.setLeafSize(0.02f, 0.02f, 0.02f);

vox.filter(*pcl2_ptrB);

但这些甚至都没有编译:

//the next 3 functions do NOT compile:

Eigen::Vector4f xyz_centroid; 

pcl::compute3DCentroid (*pcl2_ptrB, xyz_centroid);

float curvature;

Eigen::Vector4f plane_parameters;   

pcl::computePointNormal(*pcl2_ptrB, plane_parameters, curvature); 

Eigen::Affine3f A(Eigen::Affine3f::Identity());

pcl::transformPointCloud(*pcl2_ptrB, *pcl2_ptrC, A);  

我无法发现哪些功能接受哪些对象。理想情况下,并非所有PCL函数都接受pcl::PCLPointCloud2个参数吗?

2 个答案:

答案 0 :(得分:4)

pcl::PCLPointCloud2 is a ROS (Robot Operating System) message type replacing the old sensors_msgs::PointCloud2. Hence, it should only be used when interacting with ROS. (see an example here)

If needed, PCL provides two functions to convert from one type to the other:

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

Extra Information

fromPCLPointCloud2 and toPCLPointCloud2 are PCL library functions for conversions. ROS has wrappers for those functions in pcl_conversions/pcl_conversions.h that you should use instead. These will call the right combinations of functions to convert between the message and templated format.

答案 1 :(得分:1)

作为Albert所说的 For ROS Hydro and later (if you are using ROS)的后续行动,PCL已经完成了从ROS中删除所有依赖项的工作。这意味着pcl创建了一组几乎与相应的ROS消息相同的类,以便最小化pcl用户的API破坏。使用"now depracated" sensor_msgs::PointCloud2的PointCloud用户现在被要求使用pcl_conversions包,此包实现转换from/to sensor_msgs::PointCloud2 to/from) pcl::PointCloud,并且应包括:

#include <pcl_conversions/pcl_conversions.h>

并且ROS代码应该修改如下:

void foo(const sensor_msgs::PointCloud2 &pc)
{
  pcl::PCLPointCloud2 pcl_pc;
  pcl_conversions::toPCL(pc, pcl_pc);
  pcl::SomePCLFunction(pcl_pc);
  ...
}

此外,ROS社区不再将pcl打包为catkin包,因此任何直接依赖于pcl的包都应该使用新的rosdep规则libpcl-all和libpcl-all-dev并跟随PCL开发人员&#39 ;在CMake中使用PCL的指南。通常这意味着package.xml将改变如下:

find_package(PCL REQUIRED)
...
include_directories(${PCL_INCLUDE_DIRS})
...
target_link_libraries(<YOUR_TARGET> ${PCL_LIBRARIES})

有关迁移规则的更多信息,请访问hereherehere