pcl去除无强度地面点云代码
时间: 2023-09-10 08:15:28 浏览: 109
使用PCL库去除无强度地面点云的代码如下:
```cpp
#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/filters/extract_indices.h>
#include <pcl/segmentation/sac_segmentation.h>
#include <pcl/segmentation/extract_clusters.h>
int main(int argc, char** argv)
{
if (argc < 2)
{
std::cerr << "Please provide input file." << std::endl;
return -1;
}
// Load input file
pcl::PointCloud<pcl::PointXYZI>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZI>);
if (pcl::io::loadPCDFile(argv[1], *cloud) == -1)
{
std::cerr << "Failed to read input file." << std::endl;
return -1;
}
// Remove ground points
pcl::ExtractIndices<pcl::PointXYZI> extract;
pcl::PointIndices::Ptr ground_indices(new pcl::PointIndices());
pcl::ModelCoefficients::Ptr coefficients(new pcl::ModelCoefficients());
pcl::SACSegmentation<pcl::PointXYZI> segmentation;
segmentation.setModelType(pcl::SACMODEL_PLANE);
segmentation.setMethodType(pcl::SAC_RANSAC);
segmentation.setDistanceThreshold(0.2);
segmentation.setInputCloud(cloud);
segmentation.segment(*ground_indices, *coefficients);
extract.setInputCloud(cloud);
extract.setIndices(ground_indices);
extract.setNegative(true);
pcl::PointCloud<pcl::PointXYZI>::Ptr filtered_cloud(new pcl::PointCloud<pcl::PointXYZI>);
extract.filter(*filtered_cloud);
// Save output file
pcl::io::savePCDFileASCII("filtered_cloud.pcd", *filtered_cloud);
std::cout << "Filtered cloud saved to filtered_cloud.pcd" << std::endl;
return 0;
}
```
这段代码使用了PCL库中的`SACSegmentation`和`ExtractIndices`类,首先对点云进行平面分割,分割出地面点云的索引和系数,然后使用`ExtractIndices`类将地面点云从原始点云中移除。
阅读全文