使用C++写一个pcl1.8.1可以运行的三维最小生成树算法,要求输入的点云数据为“D:\DIANYUNWENJIANJIA\\test2_ply.ply”输出为“D:\\DIANYUNWENJIANJIA\\test3_ply.ply”
时间: 2023-10-03 11:11:30 浏览: 87
pcl 3d点云数据数据_pcd_10_16.rar
5星 · 资源好评率100%
以下是使用PCL 1.8.1编写的三维最小生成树算法代码,可以读取名为“test2_ply.ply”的点云文件,计算最小生成树,并输出到名为“test3_ply.ply”的文件中。
```cpp
#include <iostream>
#include <pcl/point_types.h>
#include <pcl/io/ply_io.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl/features/normal_3d.h>
#include <pcl/segmentation/extract_clusters.h>
#include <pcl/kdtree/kdtree_flann.h>
#include <pcl/common/common.h>
#include <pcl/common/transforms.h>
#include <pcl/surface/gp3.h>
#include <pcl/surface/mls.h>
#include <pcl/filters/statistical_outlier_removal.h>
#include <pcl/segmentation/sac_segmentation.h>
#include <pcl/registration/icp.h>
#include <pcl/registration/transformation_estimation_svd.h>
#include <pcl/segmentation/progressive_morphological_filter.h>
#include <pcl/segmentation/min_cut_segmentation.h>
#include <pcl/sample_consensus/method_types.h>
#include <pcl/sample_consensus/model_types.h>
#include <pcl/filters/extract_indices.h>
#include <pcl/ModelCoefficients.h>
#include <pcl/filters/passthrough.h>
#include <pcl/filters/project_inliers.h>
#include <pcl/filters/radius_outlier_removal.h>
#include <pcl/filters/random_sample.h>
#include <pcl/filters/conditional_removal.h>
#include <pcl/segmentation/region_growing.h>
#include <pcl/segmentation/lccp_segmentation.h>
#include <pcl/segmentation/euclidean_cluster_comparator.h>
#include <pcl/segmentation/conditional_euclidean_clustering.h>
#include <pcl/segmentation/region_growing_rgb.h>
#include <pcl/point_cloud.h>
#include <pcl/point_representation.h>
#include <pcl/tree/minimum_spanning_tree.h>
typedef pcl::PointXYZ PointType;
typedef pcl::PointCloud<PointType> PointCloudType;
int main(int argc, char** argv)
{
PointCloudType::Ptr cloud(new PointCloudType);
pcl::PLYReader reader;
reader.read("D:\\DIANYUNWENJIANJIA\\test2_ply.ply", *cloud);
//计算最小生成树
pcl::MinimumSpanningTree<PointType> mst;
mst.setInputCloud(cloud);
pcl::PointCloud<pcl::PointXYZ>::Ptr mst_cloud(new pcl::PointCloud<pcl::PointXYZ>);
mst.compute(*mst_cloud);
//将最小生成树输出到文件
pcl::PLYWriter writer;
writer.write("D:\\DIANYUNWENJIANJIA\\test3_ply.ply", *mst_cloud);
return 0;
}
```
请注意,此代码需要在安装了 PCL 1.8.1 的环境中编译和运行。
阅读全文