水毕设水的过分了,感觉得认真做点儿东西了,毕设主要使用激光雷达和RGBD,摄像头
均需要PointCloud数据类型,毕设中使用遍历点云呢,觉得自己太蠢了,学学PCL库
提升提升算法效率
自己买了本书。。。感觉很垃圾。。。就不推荐了,不过配套源码还可以,不过有点儿小错(需要的留邮箱吧)
更推荐官方教程http://wiki.ros.org/pcl_ros
这里我使用读realsense的点云数据
realsense的安装教程
https://github.com/IntelRealSense/librealsense/blob/master/doc/distribution_linux.md
ros_realsense的安装教程
https://github.com/IntelRealSense/realsense-ros
#include <ros/ros.h>
// PCL specific includes
#include <sensor_msgs/PointCloud2.h>
#include <pcl_conversions/pcl_conversions.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
ros::Publisher pub;
typedef pcl::PointCloud<pcl::PointXYZ> PointCloud;
#include <pcl_ros/point_cloud.h>
void
cloud_cb (const sensor_msgs::PointCloud2ConstPtr& input)
{
// 声明存储原始数据与滤波后的数据的点云的 格式
pcl::PCLPointCloud2* cloud = new pcl::PCLPointCloud2; //原始的点云的数据格式
pcl::PCLPointCloud2ConstPtr cloudPtr(cloud);
// 转化为PCL中的点云的数据格式
pcl_conversions::toPCL(*input, *cloud);
pub.publish (*cloud);
}
int
main (int argc, char** argv)
{
// Initialize ROS
ros::init (argc, argv, "ros_pcl2pcl");
ros::NodeHandle nh;
// Create a ROS subscriber for the input point cloud
//"/camera/depth/color/points"realsense发布的点云数据
ros::Subscriber sub = nh.subscribe ("/camera/depth/color/points", 1, cloud_cb);
// Create a ROS publisher for the output point cloud
pub = nh.advertise<pcl::PCLPointCloud2> ("output", 1);
// Spin
ros::spin ();
}
主要函数
pcl_conversions::toPCL(*input, *cloud);
包含在pcl_conversions.h中
可以将输入的sensor::PointCLoud2数据类型转换成pcl::PCLPointCloud2
并且这种数据类型是直接可以使用ROS进行publish的
CMake中链接的库
find_package(catkin REQUIRED COMPONENTS
OpenCV REQUIRED
pcl_conversions
pcl_ros
roscpp
sensor_msgs
cv_bridge
std_msgs
image_transport
)
效果如图所示,经过测试,KinectV2的点云同样ok,基本点云格式都可以进行转换
从而方便使用PCL库
pcl::PCLPointCloud2与sensor_msgs::PointCloud2转换主要就是这四个函数。
inline
void fromPCL(const pcl::PCLPointCloud2 &pcl_pc2, sensor_msgs::PointCloud2 &pc2)
{
copyPCLPointCloud2MetaData(pcl_pc2, pc2);
pc2.data = pcl_pc2.data;
}
inline
void moveFromPCL(pcl::PCLPointCloud2 &pcl_pc2, sensor_msgs::PointCloud2 &pc2)
{
copyPCLPointCloud2MetaData(pcl_pc2, pc2);
pc2.data.swap(pcl_pc2.data);
}
inline
void toPCL(const sensor_msgs::PointCloud2 &pc2, pcl::PCLPointCloud2 &pcl_pc2)
{
copyPointCloud2MetaData(pc2, pcl_pc2);
pcl_pc2.data = pc2.data;
}
inline
void moveToPCL(sensor_msgs::PointCloud2 &pc2, pcl::PCLPointCloud2 &pcl_pc2)
{
copyPointCloud2MetaData(pc2, pcl_pc2);
pcl_pc2.data.swap(pc2.data);
}