zl程序教程

您现在的位置是:首页 >  后端

当前栏目

3d激光雷达开发(PassThrough滤波器)

3D开发 滤波器 激光雷达
2023-09-27 14:27:10 时间

【 声明:版权所有,欢迎转载,请勿用于商业用途。 联系信箱:feixiaoxing @163.com】

        这个滤波器可能是最简单的那一类滤波器。有点类似于opencv里面的roi,也就是感兴趣区域。简单来说,这个滤波器就是对点云数据做一个裁剪,把某一个轴上面的数据段保留下来,或者剔除。原来的代码链接在这,https://pcl.readthedocs.io/projects/tutorials/en/master/passthrough.html#passthrough

1、准备passthrough.cpp文件

#include <iostream>
#include <pcl/point_types.h>
#include <pcl/filters/passthrough.h>

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>);

  // Fill in the cloud data
  cloud->width  = 10;
  cloud->height = 1;
  cloud->points.resize (cloud->width * cloud->height);

  for (auto& point: *cloud)
  {
    point.x = 1024 * rand () / (RAND_MAX + 1.0f);
    point.y = 1024 * rand () / (RAND_MAX + 1.0f);
    point.z = 1024 * rand () / (RAND_MAX + 1.0f);
  }

  std::cerr << "Cloud before filtering: " << std::endl;
  for (const auto& point: *cloud)
    std::cerr << "    " << point.x << " "
                        << point.y << " "
                        << point.z << std::endl;

  // Create the filtering object
  pcl::PassThrough<pcl::PointXYZ> pass;
  pass.setInputCloud (cloud);
  pass.setFilterFieldName ("z");
  pass.setFilterLimits (0.0, 10.0);
  //pass.setFilterLimitsNegative (true);
  pass.filter (*cloud_filtered);

  std::cerr << "Cloud after filtering: " << std::endl;
  for (const auto& point: *cloud_filtered)
    std::cerr << "    " << point.x << " "
                        << point.y << " "
                        << point.z << std::endl;

  return (0);
}

2、代码分析

        整个代码段里面,最重要的部分就是pass.setFilterFieldName和pass.setFilterLimits这两句话。前者是说面对哪一个方向的数据进行处理,后面一句设置处理的范围。后面还有一句,pass.setFilterLimitsNegative是说保留范围内的数据,还是保留范围之外的数据。

3、准备CMakeLists.txt

cmake_minimum_required(VERSION 3.5 FATAL_ERROR)

project(passthrough)

find_package(PCL 1.2 REQUIRED)

include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

add_executable (passthrough passthrough.cpp)
target_link_libraries (passthrough ${PCL_LIBRARIES})

4、编译生成sln工程,开始链接

        cmake之后,应该可以正常编译成功

5、执行passthrough.exe

        执行过程中,可能出现dll不全的情况,补全就好了。

        此外,执行过程中还可能出现filter之后,没有数据的情况,这主要是因为setFilterLimits过小的原因,可以设置的再大一点,另外随机生成的数据再多一点,效果也会好很多。