PCL库-直通滤波器

一 直通滤波器

直通滤波器:对指定维度(X,Y,Z,BGR等)进行某一个范围滤波,可以删除这个范围内部点,也可以删除这个范围外部的点

二 关键函数

1)实例化:

pcl::PassThroughpcl::PointXYZ pass;//实例化直通滤波器

2)载入点云

pcl::PassThroughpcl::PointXYZ::setInputCloud(pcl::PointCloud::Ptr)

3)设置滤波方向

pcl::PassThroughpcl::PointXYZ::setFilterFieldName(std::string)

4)设置滤波范围

pcl::PassThroughpcl::PointXYZ::setFilterLimits(double, double)

三 示例

#include 
#include 
#include 
#include 
int main (int argc, char** argv)
{ srand(time(0));
  pcl::PointCloud::Ptr cloud (new pcl::PointCloud);
  pcl::PointCloud::Ptr cloud_filtered (new pcl::PointCloud);
  //填入点云数据
  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 = rand () / (RAND_MAX + 1.0f)-0.5;
    cloud->points[i].y = rand () / (RAND_MAX + 1.0f)-0.5;
    cloud->points[i].z = rand () / (RAND_MAX + 1.0f)-0.5;
  }
  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;
  // 创建滤波器对象
  pcl::PassThrough pass;//创建滤波器对象
  pass.setInputCloud (cloud);			//设置待滤波的点云
  pass.setFilterFieldName ("z");		//设置在Z轴方向上进行滤波
  pass.setFilterLimits (0.0, 1.0);		//设置滤波范围为0~1,在范围之外的点会被剪除
  //pass.setFilterLimitsNegative (true);//是否反向过滤,默认为false
  pass.filter (*cloud_filtered);		//开始过滤
 
  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_filtered->points[i].z << std::endl;
  return (0);
}

你可能感兴趣的:(pcl,c++)