使用RadiusOutlierRemoval移除离群点

可以删除在输入的点云一定范围内没有至少达到足够多近邻的所有数据点。

关键成员函数:

void pcl::RadiusOutlierRemoval< PointT >::setRadiusSearch(double radius)

Set the radius of the sphere that will determine which points are neighbors.  

The number of points within this distance from the query point will need to be equal or greater than setMinNeighborsInRadius() in order to be classified as an inlier point (i.e. will not be filtered). 

void pcl::RadiusOutlierRemoval< PointT >::setMinNeighborsInRadius(int min_pts)

Set the number of neighbors that need to be present in order to be classified as an inlier.

The number of points within setRadiusSearch() from the query point will need to be equal or greater than this number in order to be classified as an inlier point (i.e. will not be filtered). 

#include<iostream>
#include<pcl\point_cloud.h>
#include<pcl\point_types.h>
#include<pcl\io\io.h>
#include<pcl\filters\radius_outlier_removal.h>
using namespace std;
int main()
{
	pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
	pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered(new pcl::PointCloud<pcl::PointXYZ>);
	cloud->width=5;
	cloud->height=1;
	cloud->points.resize(cloud->width*cloud->height);
	for(size_t i=0;i<cloud->points.size();i++)
	{
		cloud->points[i].x=1024*rand()/(RAND_MAX+1.0f);
		cloud->points[i].y=1024*rand()/(RAND_MAX+1.0f);
		cloud->points[i].z=1024*rand()/(RAND_MAX+1.0f);
	}
	pcl::RadiusOutlierRemoval<pcl::PointXYZ> outrem;
	outrem.setInputCloud(cloud);
	outrem.setRadiusSearch(0.8);
	outrem.setMinNeighborsInRadius(2);
	outrem.filter(*cloud_filtered);
	std::cerr<<"cloud before filtering:"<<std::endl;
	for(size_t i=0;i<cloud->points.size();i++)
		std::cerr<<' '<<cloud->points[i].x<<' '<<cloud->points[i].y<<' '<<cloud->points[i].z<<std::endl;
	std::cerr<<"cloud after filtering:"<<std::endl;
	for(size_t i=0;i<cloud_filtered->points.size();i++)
		std::cerr<<' '<<cloud_filtered->points[i].x<<' '<<cloud_filtered->points[i].y<<' '<<cloud->points[i].z<<std::endl;
	system("pause");
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值