#include <iostream> #include <pcl/io/pcd_io.h> #include <pcl/point_types.h> #include <pcl/io/ply_io.h> int main(int argc, char** argv) { pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>); if (pcl::io::loadPLYFile<pcl::PointXYZ>("model.ply", *cloud) == -1) //* load the file { PCL_ERROR("Couldn't read file test_pcd.pcd "); system("PAUSE"); 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 << std::endl; //std::string filename("test.pcd"); //pcl::PCDWriter writer; //writer.write(filename, *cloud); system("PAUSE"); return (0); }
上面这段代码从ply文件中读入点云
#include <iostream> #include <pcl/io/pcd_io.h> #include <pcl/point_types.h> #include <pcl/io/ply_io.h> #include <pcl/visualization/cloud_viewer.h> int main(int argc, char** argv) { pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>); if (pcl::io::loadPLYFile<pcl::PointXYZ>("model.ply", *cloud) == -1) //* load the file { PCL_ERROR("Couldn't read file test_pcd.pcd "); system("PAUSE"); return (-1); } //pcl::StatisticalOutlierRemoval::applyFileter() pcl::visualization::CloudViewer viewer("Viewer"); viewer.showCloud(cloud); system("PAUSE"); return (0); }
将读入的ply文件可视化出来