在本教程中,我们将学习如何将点云数据写入PCD文件里面
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| #include <iostream> #include <pcl/io/pcd_io.h> #include <pcl/point_types>
int main(int argc.char** argv){ //创建一个点云对象 pcl::PointCloud<pcl::PointXYZ> cloud; //设置其参数 cloud.width=5;//宽度 cloud.height=1;//高度 cloud.is_dense=false;//是否是密集型 cloud.points.resize(cloud.width*cloud.height);//重新计算cloud大小 //随机赋值cloud内的点, for(auto& point:cloud){ point.x=1024*rand()/(RAND_MAX+1.0f); point.y=1024*rand()/(RAND_MAX+1.0f); point.z=1024*rand()/(RAND_MAX+1.0f); } //将cloud存入到test_pcd.pcd中 pcd::io::savePCDFileASCII("test_pcd.pcd",cloud); //将cloud的信息打印出来 std::cerr<<"saved"<<cloud.size()<<" data points to test_pcd.pcd"<<std::endl; for(const auto& point:cloud){ std::cerr<<point.x<<" " <<point.y<<" " <<point.z<<" " <<std::endl; } return (0); }
|