1写pcd点云
cloud转pcd
pcl::PointCloudpcl::PointXYZ cloud;
pcl::io::savePCDFileASCII (“test.pcd”, cloud);
#include <ros/ros.h>
#include <pcl/point_cloud.h>
#include <pcl_conversions/pcl_conversions.h>
#include <sensor_msgs/PointCloud2.h>
#include <pcl/io/pcd_io.h>
void cloudCB(const sensor_msgs::PointCloud2 &input)
{
pcl::PointCloud<pcl::PointXYZ> cloud;
pcl::fromROSMsg(input, cloud);
pcl::io::savePCDFileASCII ("test.pcd", cloud);
}
main (int argc, char **argv)
{
ros::init (argc, argv, "pcl_write");
ROS_INFO("Started PCL write node");
ros::NodeHandle nh;
ros::Subscriber bat_sub = nh.subscribe("pcl_output", 10, cloudCB);
ros::spin();
return 0;
}
pcl_output的原点云 cloud.width = 50000 ; cloud.height = 1;
生成pcd文件后,使用终端查看点云
$ pcl_viewer test.pcd
2读pcd点云并发布
读取pcd转cloud
pcl::PointCloudpcl::PointXYZ cloud;
pcl::io::loadPCDFile (“test.pcd”, cloud);
#include <ros/ros.h>
#include <pcl/point_cloud.h>
#include <pcl_conversions/pcl_conversions.h>
#include <sensor_msgs/PointCloud2.h>
#include <pcl/io/pcd_io.h>
main(int argc, char **argv)
{
ros::init (argc, argv, "pcl_read");
ROS_INFO("Started PCL read node");
ros::NodeHandle nh;
ros::Publisher pcl_pub = nh.advertise<sensor_msgs::PointCloud2> ("pcl_output", 1);
sensor_msgs::PointCloud2 output;
pcl::PointCloud<pcl::PointXYZ> cloud;
pcl::io::loadPCDFile ("test.pcd", cloud);
pcl::toROSMsg(cloud, output);
output.header.frame_id = "point_cloud";
ros::Rate loop_rate(1);
while (ros::ok())
{
pcl_pub.publish(output);
ros::spinOnce();
loop_rate.sleep();
}
return 0;
}