在ros中保存点云数据为pcd(ascii)格式

其他步骤类似之前写的文章“在ros中使用pcl实现点云滤波”。

主要的代码为:

#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, "savePCDFileASCII");

    ROS_INFO("Started PCL write node");

    ros::NodeHandle nh;
    ros::Subscriber bat_sub = nh.subscribe("livox/lidar", 1, cloudCB);

    ros::spin();
    return 0;
}

需要完善:
目前只是保存单帧数据,需要添加保存多个pcd数据的功能。。

猜你喜欢

转载自blog.csdn.net/sj775973722/article/details/115111849