本文主要是介绍【PCL】(八)PassThrough滤波器滤除点云指定范围以外或以内的点,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
(八)PassThrough滤波器
以下代码实现沿着指定的维度滤除指定范围以外或以内的点。
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>);// 5个点的点云,坐标值介于-1和1之间//https://blog.csdn.net/qq_45182713/article/details/123760203cloud->width = 5;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;// 创建PassThrough滤波器对象 pcl::PassThrough<pcl::PointXYZ> pass;pass.setInputCloud (cloud);pass.setFilterFieldName ("z"); // 指定滤波维度pass.setFilterLimits (0.0, 1.0); // 指定滤波范围(0.0,1.0)pass.setNegative (true); // false: 滤除范围外的点(默认);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);
}
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})
编译并运行:
./passthrough
(1)沿着x轴滤波: pass.setFilterFieldName (“x”);
Cloud before filtering: 0.352222 -0.151883 -0.106395-0.397406 -0.473106 0.292602-0.731898 0.667105 0.441304-0.734766 0.854581 -0.0361733-0.4607 -0.277468 -0.916762
Cloud after filtering: 0.352222 -0.151883 -0.106395
(2)沿着y轴滤波: pass.setFilterFieldName (“y”);
Cloud before filtering: 0.352222 -0.151883 -0.106395-0.397406 -0.473106 0.292602-0.731898 0.667105 0.441304-0.734766 0.854581 -0.0361733-0.4607 -0.277468 -0.916762
Cloud after filtering: -0.731898 0.667105 0.441304-0.734766 0.854581 -0.0361733
(3)沿着z轴滤波: pass.setFilterFieldName (“z”);
Cloud before filtering: 0.352222 -0.151883 -0.106395-0.397406 -0.473106 0.292602-0.731898 0.667105 0.441304-0.734766 0.854581 -0.0361733-0.4607 -0.277468 -0.916762
Cloud after filtering: -0.397406 -0.473106 0.292602-0.731898 0.667105 0.441304
(4)滤除范围内的点: pass.setFilterFieldName (“z”); pass.setNegative (true);
Cloud before filtering: 0.352222 -0.151883 -0.106395-0.397406 -0.473106 0.292602-0.731898 0.667105 0.441304-0.734766 0.854581 -0.0361733-0.4607 -0.277468 -0.916762
Cloud after filtering: 0.352222 -0.151883 -0.106395-0.734766 0.854581 -0.0361733-0.4607 -0.277468 -0.916762
这篇关于【PCL】(八)PassThrough滤波器滤除点云指定范围以外或以内的点的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!