摘要:#include #include #include #include #include
需要说明一下的是环境中需要配置pcl和laslib库,此次vs2022配置了pcl1.14.1以及laslib
#include #include #include #include#include
#include
#include
#include
// 用于保存PCD文件pcl::PointCloud
::Ptr global_cloud(new pcl::PointCloud
);int main{ try { // 设置las文件路径 const char* las_File = "tree.las"; // 替换为你的las文件路径 // 创建LASreader对象 LASreadOpener lasreadopener; lasreadopener.set_file_name(las_file); // 打开las文件 LASreader* lasreader = lasreadopener.open; if (!lasreader) { std::cout read_point) { pcl::PointXYZ point; point.x = lasreader->point.get_x; point.y = lasreader->point.get_y; point.z = lasreader->point.get_z; global_cloud->points.push_back(point); } global_cloud->width = global_cloud->points.size; global_cloud->height = 1; global_cloud->is_dense = true; // 将点云中心移到原点 Eigen::Vector4f centroid; pcl::compute3DCentroid(*global_cloud, centroid); for (auto& point : global_cloud->points) { point.x -= centroid[0]; point.y -= centroid[1]; point.z -= centroid[2]; } cout points.size setBackgroundColor(0, 0, 0); // 黑色背景 // 设置点云为白色 pcl::visualization::PointCloudColorHandlerCustom
color_handler(global_cloud, 255, 255, 255); viewer->addPointCloud
(global_cloud, color_handler, "sample cloud"); viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "sample cloud"); // 主循环 while (!viewer->wasStopped) { viewer->spinOnce(100); } // 关闭las文件 lasreader->close; delete lasreader; std::cout
来源:新手村养牛