如何仅使用pcl 1.8将ros PointCloud2转换为pcl Pointcloud2?

时间:2018-04-25 22:07:24

标签: ros point-cloud-library

我正在使用ros,但我需要pcl 1.8的一些新功能。这就是为什么我使用find_package(PCL 1.8 Required)将其包含在系统依赖项中并且不能包含任何ros_pcl包的原因,因为我在邮件列表中读到了关于这个问题的混合ros_pcl和独立的pcl是一个坏主意。

现在我无法找到一种方法如何将ros sensor_msgs::PointCloud2 pointcloud转换为pcl::PointCloud2 pointcloud。我只发现void pcl::toPCLPointCloud2 (const pcl::PointCloud< PointT >& cloud, pcl::PCLPointCloud2 & msg)的类型错误,并给我一个编译错误。

现在pcl_conversion包中有这个函数:void pcl::fromROSMsg (const sensor_msgs::PointCloud2 &cloud, pcl::PointCloud< T > &pcl_cloud)我成功地使用它来尝试它,但是后来不能同时使用pcl 1.8。现在我的问题是:自己复制/实现函数fromROSMsg能够使用1.8是否最好?或者有更好的方法来解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

如果您对此仍然有疑问,请按照以下提示进行操作

在CMakeLists.txt

find_package(catkin_simple REQUIRED)
catkin_simple(ALL_DEPS_REQUIRED)

.
.
.

find_package(PCL 1.8 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

然后将${PCL_LIBRARIES}添加到target_link_libraries中。

要在1.8版本中进行转换,我使用了这种方式,并且有效。

pcl::PointCloud<pcl::PointXYZI> in_cloud;
pcl::fromROSMsg(in_msg, in_cloud);

其中in_msg是const sensor_msgs::PointCloud2&的类型。