【PCL】(二十七)基于法线差的点云分割
(二十七)基于法线差的点云分割

图片来源
提出这个方法的论文:Difference of Normals as a Multi-Scale Operator in Unorganized Point Clouds
算法流程:
-
在大尺度的范围内(半径 r 1 r_1 r1)估计每个点的法线;
-
在晓尺度的范围(半径 r 2 r_2 r2)估计每个点的法线;
-
计算法线差(Difference of Normals (DoN));

-
根据设定的法线差阈值过滤点;
-
对剩余的点进行欧几里得分割。
don_segmentation.cpp
/*** @file don_segmentation.cpp* Difference of Normals Example for PCL Segmentation Tutorials.** @author Yani Ioannou* @date 2012-09-24*/
#include <string>
#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>
#include <pcl/search/organized.h>
#include <pcl/search/kdtree.h>
#include <pcl/features/normal_3d_omp.h>
#include <pcl/filters/conditional_removal.h>
#include <pcl/segmentation/extract_clusters.h>
#include <pcl/features/don.h>using namespace pcl;int main (int argc, char *argv[])
{///The smallest scale to use in the DoN filter.double scale1;///The largest scale to use in the DoN filter.double scale2;///The minimum DoN magnitude to threshold bydouble threshold;///segment scene into clusters with given distance tolerance using euclidean clusteringdouble segradius;if (argc < 6){std::cerr << "usage: " << argv[0] << " inputfile smallscale largescale threshold segradius" << std::endl;exit (EXIT_FAILURE);}/// the file to read from.std::string infile = argv[1];/// small scalestd::istringstream (argv[2]) >> scale1;/// large scalestd::istringstream (argv[3]) >> scale2;std::istringstream (argv[4]) >> threshold; // threshold for DoN magnitudestd::istringstream (argv[5]) >> segradius; // threshold for radius segmentation// Load cloud in blob formatpcl::PCLPointCloud2 blob;pcl::io::loadPCDFile (infile.c_str (), blob);pcl::PointCloud<PointXYZRGB>::Ptr cloud (new pcl::PointCloud<PointXYZRGB>);pcl::fromPCLPointCloud2 (blob, *cloud);// OrganizedNeighbor适用于有组织的数据。KDTree适用于无组织的数据pcl::search::Search<PointXYZRGB>::Ptr tree;if (cloud->isOrganized ()){tree.reset (new pcl::search::OrganizedNeighbor<PointXYZRGB> ());}else{tree.reset (new pcl::search::KdTree<PointXYZRGB> (false));}// Set the input pointcloud for the search treetree->setInputCloud (cloud);if (scale1 >= scale2){std::cerr << "Error: Large scale must be > small scale!" << std::endl;exit (EXIT_FAILURE);}// 计算每个点小尺度和大尺度的法线// 通过OpenMP多线程,使用处理器中的多个内核来计算法线pcl::NormalEstimationOMP<PointXYZRGB, PointNormal> ne; // PointNormal-float x,y,z,normal[3], curvaturene.setInputCloud (cloud);ne.setSearchMethod (tree);// 设置一个在所有法线计算中使用的视点,确保了在不同尺度上估计的法线的基本方向一致。ne.setViewPoint (std::numeric_limits<float>::max (), std::numeric_limits<float>::max (), std::numeric_limits<float>::max ());// calculate normals with the small scalestd::cout << "Calculating normals for scale..." << scale1 << std::endl;pcl::PointCloud<PointNormal>::Ptr normals_small_scale (new pcl::PointCloud<PointNormal>);ne.setRadiusSearch (scale1);ne.compute (*normals_small_scale);// calculate normals with the large scalestd::cout << "Calculating normals for scale..." << scale2 << std::endl;pcl::PointCloud<PointNormal>::Ptr normals_large_scale (new pcl::PointCloud<PointNormal>);ne.setRadiusSearch (scale2);ne.compute (*normals_large_scale);// Create output cloud for DoN resultsPointCloud<PointNormal>::Ptr doncloud (new pcl::PointCloud<PointNormal>);copyPointCloud (*cloud, *doncloud);std::cout << "Calculating DoN... " << std::endl;// DoN 估计模板的3个参数<第一个对应于输入点云类型,第二个对应于为点云估计的法线类型.第三个对应于输出类型pcl::DifferenceOfNormalsEstimation<PointXYZRGB, PointNormal, PointNormal> don;don.setInputCloud (cloud);don.setNormalScaleLarge (normals_large_scale);don.setNormalScaleSmall (normals_small_scale);if (!don.initCompute ()){std::cerr << "Error: Could not initialize DoN feature operator" << std::endl;exit (EXIT_FAILURE);}// Compute DoNdon.computeFeature (*doncloud);// Save DoN featurespcl::PCDWriter writer;writer.write<pcl::PointNormal> ("don.pcd", *doncloud, false); std::cout << "Filtering out DoN mag <= " << threshold << "..." << std::endl;// 设定滤波条件,根据点的法线差矢量过滤点 pcl::ConditionOr<PointNormal>::Ptr range_cond (new pcl::ConditionOr<PointNormal> ());// "curvature" :过滤DoN的l2范数小于threshold的点range_cond->addComparison (pcl::FieldComparison<PointNormal>::ConstPtr (new pcl::FieldComparison<PointNormal> ("curvature", pcl::ComparisonOps::GT, threshold)));// 创建条件滤波器pcl::ConditionalRemoval<PointNormal> condrem;condrem.setCondition (range_cond);condrem.setInputCloud (doncloud);pcl::PointCloud<PointNormal>::Ptr doncloud_filtered (new pcl::PointCloud<PointNormal>);// Apply filtercondrem.filter (*doncloud_filtered);doncloud = doncloud_filtered;// Save filtered outputstd::cout << "Filtered Pointcloud: " << doncloud->size () << " data points." << std::endl;writer.write<pcl::PointNormal> ("don_filtered.pcd", *doncloud, false); // 欧几里得聚类分割std::cout << "Clustering using EuclideanClusterExtraction with tolerance <= " << segradius << "..." << std::endl;pcl::search::KdTree<PointNormal>::Ptr segtree (new pcl::search::KdTree<PointNormal>);segtree->setInputCloud (doncloud);std::vector<pcl::PointIndices> cluster_indices;pcl::EuclideanClusterExtraction<PointNormal> ec;ec.setClusterTolerance (segradius);ec.setMinClusterSize (50);ec.setMaxClusterSize (100000);ec.setSearchMethod (segtree);ec.setInputCloud (doncloud);ec.extract (cluster_indices);int j = 0;for (const auto& cluster : cluster_indices){pcl::PointCloud<PointNormal>::Ptr cloud_cluster_don (new pcl::PointCloud<PointNormal>);for (const auto& idx : cluster.indices){cloud_cluster_don->points.push_back ((*doncloud)[idx]);}cloud_cluster_don->width = cloud_cluster_don->size ();cloud_cluster_don->height = 1;cloud_cluster_don->is_dense = true;//Save clusterstd::cout << "PointCloud representing the Cluster: " << cloud_cluster_don->size () << " data points." << std::endl;std::stringstream ss;ss << "don_cluster_" << j << ".pcd";writer.write<pcl::PointNormal> (ss.str (), *cloud_cluster_don, false);++j;}
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)project(don_segmentation)find_package(PCL 1.7 REQUIRED)include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})add_executable (don_segmentation don_segmentation.cpp)
target_link_libraries (don_segmentation ${PCL_LIBRARIES})
数据样例
编译并运行:
$ ./don_segmentation <inputfile> <smallscale> <largescale> <threshold> <segradius>
$./don_segmentation 003000.pcd 0.4 2 0.2 0.5
DoN:

根据DoN滤除点:

聚类:

相关文章:
【PCL】(二十七)基于法线差的点云分割
(二十七)基于法线差的点云分割 图片来源 提出这个方法的论文:Difference of Normals as a Multi-Scale Operator in Unorganized Point Clouds 算法流程: 在大尺度的范围内(半径 r 1 r_1 r1)估计每个点…...
智慧公厕系统的组成部分有什么?
智慧公厕系统是现代城市管理中一项重要的创新,利用物联网、互联网、大数据、云计算、自动化控制等先进的技术手段,提供高效便捷的公厕服务。从信息系统的角度来看,智慧公厕系统主要由硬件、软件和网络组成,硬件、软件和网络三大部…...
[数据集][目标检测]芒果叶病害数据集VOC+YOLO格式4000张5类别
数据集格式:Pascal VOC格式YOLO格式(不包含分割路径的txt文件,仅仅包含jpg图片以及对应的VOC格式xml文件和yolo格式txt文件) 图片数量(jpg文件个数):4000 标注数量(xml文件个数):4000 标注数量(txt文件个数):4000 标注…...
Linux: 预备
计算机结构基础 操作系统: 内核 (管理软硬件) shell(给用户使用操作系统的方式) 操作系统的目标 对硬件抽象 原因:操作系统是对软硬件资源管理的应用软件抽象:内存管理, 进程管理, 文件管理, 驱动管理软件:驱动程序(给软件提供访问硬件的软件)硬件:磁盘(对应文件), 网卡等隔离…...
ChatGPT 升级出现「我们未能验证您的支付方式/we are unable to authenticate」怎么办?
ChatGPT 升级出现「我们未能验证您的支付方式/we are unable to authenticate」怎么办? 在订阅 ChatGPT Plus 时,有时候会出现以下报错 : We are unable to authenticate your payment method. 我们未能验证您的支付方式。 出现 unable to a…...
JavaWeb - 3 - JavaScript(JS)
JavaScript(JS)官方参考文档:JavaScript 教程 JavaScript(简称:JS)是一门跨平台、面向对象的脚本语言,是用来控制网页行为的,它能使网页可交互(脚本语言就不需要编译,直接通过浏览器…...
基于springboot+vue的美食烹饪互动平台
博主主页:猫头鹰源码 博主简介:Java领域优质创作者、CSDN博客专家、阿里云专家博主、公司架构师、全网粉丝5万、专注Java技术领域和毕业设计项目实战,欢迎高校老师\讲师\同行交流合作 主要内容:毕业设计(Javaweb项目|小程序|Pyt…...
linux中操作服务器常用命令
在Linux中操作服务器时,常用的命令包括: ls:列出目录内容。 cd:切换目录。 pwd:显示当前所在的目录路径。 mkdir:创建一个新的目录。 rmdir:删除一个空的目录。 cp:复制文件或目录。…...
最简k8s部署(AWS Load Balancer Controller使用)
问题 我需要在k8s集群里面部署springboot服务,通过k8s ingress访问集群内部的springboot服务,应该怎么做? 这里假设已经准备好k8s集群,而且也准备好springboot服务的运行镜像了。这里我们将精力放在k8s服务编排上面。 一图胜千言…...
差距拉开了!量化大厂最新业绩排行曝光!
经历了一月份的失落和二月份绝地反攻,量化大厂们的整体业绩备受关注。 而今年2月份的量化战绩,甚为关键! 毕竟市场指数“前低后高”,基金经理与投资人开年以来,共同经历了“惊心动魄”的考验。 量化大厂,…...
【Web前端】Vue核心基础
文章目录 1. Vue简介2. Vue官网使用指南3. 初识Vue3.1 搭建Vue开发环境3.2 HelloWorld案例3.3 el与data的两种写法3.4 MVVM模型3.5 模板语法 4. 数据绑定4.1 v-bind单向数据绑定4.2 v-model双向数据绑定 5. 事件处理5.1 v-on绑定事件5.2 事件修饰符5.3 键盘事件 6. 计算属性6.1…...
Linux操作系统项目上传Github代码仓库指南
文章目录 1 创建SSH key2.本地git的用户名和邮箱设置3.测试连接4.创建仓库5.终端项目上传 1 创建SSH key 1.登录github官网,点击个人头像,点击Settings,然后点击SSH and GPG keys,再点击New SSH key。 Title 可以随便取,但是 key 需要通过终端生成。 Linux终端执行…...
机器学习--循环神经网路(RNN)2
在这篇文章中,我们介绍一下其他的RNN。 一.深层RNN 循环神经网络的架构是可以任意设计的,之前提到的 RNN 只有一个隐藏层,但 RNN 也可以是深层的。比如把 xt 丢进去之后,它可以通过一个隐藏层,再通过第二个隐藏层&am…...
sheng的学习笔记-AI-多分类学习:ECOC,softmax
目录:sheng的学习笔记-AI目录-CSDN博客 基本术语: 若我们欲预测的是离散值,例如“好瓜”“坏瓜”,此类学习任务称为“分类”(classification); 若欲预测的是连续值,例如西瓜成熟度0.95、0.37,…...
ChatGPT Plus 支付出现「您的银行卡被拒绝/your card has been declined」怎么办?
ChatGPT Plus 支付出现「您的银行卡被拒绝/your card has been declined」怎么办? 在订阅 ChatGPT Plus 或者 OpenAI API 时,有时候会出现已下报错 : Your card has been declined. 您的银行卡被拒绝 出现这种错误,有以下几个解…...
typescript学习(更新中)
目录 开发环境搭建类型如何声明有哪些类型编译配置文件 开发环境搭建 npm i -g typescripttsc检查是否安装成功 类型如何声明 // 先声明再赋值 let a: number a 1// 直接赋值 let b 1function sum(a: number, b: number): number {return a b } console.log(sum(1, 2))有…...
T2 小美的平衡矩阵(25分) - 美团编程题 题解
考试平台: 牛客网 题目类型: 30道单选题(60分) 2 道编程题 (15分 25分) 考试时间: 2024-03-09 (两小时) 题目描述 小美拿到了一个n*n的矩阵,其中每个元素是…...
13:大数据与Hadoop|分布式文件系统|分布式Hadoop集群
大数据与Hadoop|分布式文件系统|分布式Hadoop集群 Hadoop部署Hadoop HDFS分布式文件系统HDFS部署步骤一:环境准备HDFS配置文件 查官方手册配置Hadoop集群 日志与排错 mapreduce 分布式离线计算框架YARN集群资源管理系统步骤一:安装…...
前端知识点、技巧、webpack、性能优化(持续更新~)
1、 请求太多 页面加载慢 (webpack性能优化) 可以把 图片转换成 base64 放在src里面 减少服务器请求 但是图片会稍微大一点点 以上的方法不需要一个一个自己转化 可以在webpack 进行 性能优化 (官网有详细描述)...
红队专题-开源漏扫-巡风xunfeng源码剖析与应用
开源漏扫-巡风xunfeng 介绍主体两部分:网络资产识别引擎,漏洞检测引擎。代码赏析插件编写JSON标示符Python脚本此外系统内嵌了辅助验证功能文件结构功能 模块添加IP三. 进行扫描在这里插入图片描述 尤为重要。结合大模型技术&…...
EtherNet/IP转DeviceNet协议网关详解
一,设备主要功能 疆鸿智能JH-DVN-EIP本产品是自主研发的一款EtherNet/IP从站功能的通讯网关。该产品主要功能是连接DeviceNet总线和EtherNet/IP网络,本网关连接到EtherNet/IP总线中做为从站使用,连接到DeviceNet总线中做为从站使用。 在自动…...
高防服务器能够抵御哪些网络攻击呢?
高防服务器作为一种有着高度防御能力的服务器,可以帮助网站应对分布式拒绝服务攻击,有效识别和清理一些恶意的网络流量,为用户提供安全且稳定的网络环境,那么,高防服务器一般都可以抵御哪些网络攻击呢?下面…...
【C++从零实现Json-Rpc框架】第六弹 —— 服务端模块划分
一、项目背景回顾 前五弹完成了Json-Rpc协议解析、请求处理、客户端调用等基础模块搭建。 本弹重点聚焦于服务端的模块划分与架构设计,提升代码结构的可维护性与扩展性。 二、服务端模块设计目标 高内聚低耦合:各模块职责清晰,便于独立开发…...
【Oracle】分区表
个人主页:Guiat 归属专栏:Oracle 文章目录 1. 分区表基础概述1.1 分区表的概念与优势1.2 分区类型概览1.3 分区表的工作原理 2. 范围分区 (RANGE Partitioning)2.1 基础范围分区2.1.1 按日期范围分区2.1.2 按数值范围分区 2.2 间隔分区 (INTERVAL Partit…...
Java多线程实现之Thread类深度解析
Java多线程实现之Thread类深度解析 一、多线程基础概念1.1 什么是线程1.2 多线程的优势1.3 Java多线程模型 二、Thread类的基本结构与构造函数2.1 Thread类的继承关系2.2 构造函数 三、创建和启动线程3.1 继承Thread类创建线程3.2 实现Runnable接口创建线程 四、Thread类的核心…...
CSS设置元素的宽度根据其内容自动调整
width: fit-content 是 CSS 中的一个属性值,用于设置元素的宽度根据其内容自动调整,确保宽度刚好容纳内容而不会超出。 效果对比 默认情况(width: auto): 块级元素(如 <div>)会占满父容器…...
【C++进阶篇】智能指针
C内存管理终极指南:智能指针从入门到源码剖析 一. 智能指针1.1 auto_ptr1.2 unique_ptr1.3 shared_ptr1.4 make_shared 二. 原理三. shared_ptr循环引用问题三. 线程安全问题四. 内存泄漏4.1 什么是内存泄漏4.2 危害4.3 避免内存泄漏 五. 最后 一. 智能指针 智能指…...
