PCL读取与保存点云文件

读取与保存点云文件,以下PCD格式文件为例,PLY文件类似。


#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>

int
main (int argc, char** argv)
{
  pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGBA>);

  if (pcl::io::loadPCDFile<pcl::PointXYZRGBA> ("test_pcd.pcd", *cloud) == -1) //* load the file
  {
    PCL_ERROR ("Couldn't read file test_pcd.pcd \n");
    return (-1);
  }
  std::cout << "Loaded "
            << cloud->width * cloud->height
            << " data points from test_pcd.pcd with the following fields: "
            << std::endl;
  for (size_t i = 0; i < cloud->points.size (); ++i)
    std::cout << "    " << cloud->points[i].x
              << " "    << cloud->points[i].y
              << " "    << cloud->points[i].z
              << " "    << (int)cloud->points[i].r
              << " "    << (int)cloud->points[i].g
              << " "    << (int)cloud->points[i].b
              << std::endl;
  std::string filename("test.pcd");
  pcl::PCDWriter writer;
  writer.write(filename,*cloud);
  return (0);
}

注意:如程序,要在控制台显示r、g和b信息,需要强制转换r、g和b的格式。


你可能感兴趣的:(保存,PCD,点云,PCL读取)