PCL-基于超体聚类的LCCP点云分割

目录

  • 一、LCCP方法
  • 二、代码实现
  • 三、实验结果
  • 四、总结
  • 五、相关链接

一、LCCP方法

LCCP指的是Local Convexity-Constrained Patch,即局部凸约束补丁的意思。LCCP方法的基本思想是在图像中找到局部区域内的凸结构,并将这些结构用于分割图像或提取特征。这种方法可以帮助识别图像中的凸物体,并对它们进行分割。LCCP方法通常结合了空间和法线信息,以提高图像分割的准确性和稳定性。

LCCP算法大致可以分成两个部分:1.基于超体聚类的过分割。2.在超体聚类的基础上再聚类。
该方法流程图如下:
在这里插入图片描述

二、代码实现

#include <iostream>
#include <pcl/ModelCoefficients.h>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/sample_consensus/method_types.h>
#include <pcl/sample_consensus/model_types.h>
#include <pcl/segmentation/sac_segmentation.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/filters/extract_indices.h>
#include <boost/thread/thread.hpp>
#include <stdlib.h>
#include <cmath>
#include <limits.h>
#include <boost/format.hpp>
#include <pcl/console/parse.h>
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/visualization/point_cloud_color_handlers.h>
#include <pcl/filters/passthrough.h>
#include <pcl/segmentation/supervoxel_clustering.h>
#include <pcl/segmentation/lccp_segmentation.h>
#include <vtkPolyLine.h> 
#include <pcl/point_cloud.h>
#include <pcl/segmentation/supervoxel_clustering.h>
#include <pcl/visualization/pcl_visualizer.h>using namespace std;
typedef pcl::PointXYZ PointT;
typedef pcl::LCCPSegmentation<PointT>::SupervoxelAdjacencyList SuperVoxelAdjacencyList;
//邻接线条可视化
void addSupervoxelConnectionsToViewer(pcl::PointXYZRGBA& supervoxel_center, pcl::PointCloud<pcl::PointXYZRGBA>& adjacent_supervoxel_centers,std::string supervoxel_name, pcl::visualization::PCLVisualizer::Ptr& viewer)
{vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New();vtkSmartPointer<vtkPolyLine> polyLine = vtkSmartPointer<vtkPolyLine>::New();for (auto adjacent_itr = adjacent_supervoxel_centers.begin(); adjacent_itr != adjacent_supervoxel_centers.end(); ++adjacent_itr){points->InsertNextPoint(supervoxel_center.data);points->InsertNextPoint(adjacent_itr->data);}vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New();polyData->SetPoints(points);polyLine->GetPointIds()->SetNumberOfIds(points->GetNumberOfPoints());for (unsigned int i = 0; i < points->GetNumberOfPoints(); i++)polyLine->GetPointIds()->SetId(i, i);cells->InsertNextCell(polyLine);polyData->SetLines(cells);viewer->addModelFromPolyData(polyData, supervoxel_name);
}int main(int argc, char** argv)
{pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered(new pcl::PointCloud<pcl::PointXYZ>);pcl::PCDReader reader;// 读入点云PCD文件reader.read("E:****.pcd", *cloud);cout << "Point cloud data: " << cloud->points.size() << " points" << endl;pcl::ModelCoefficients::Ptr coefficients(new pcl::ModelCoefficients);pcl::PointIndices::Ptr inliers(new pcl::PointIndices);// 创建分割对象pcl::SACSegmentation<pcl::PointXYZ> seg;// 可选择配置,设置模型系数需要优化seg.setOptimizeCoefficients(true);// 必须配置,设置分割的模型类型、所用随机参数估计方法seg.setModelType(pcl::SACMODEL_PLANE);seg.setMethodType(pcl::SAC_RANSAC);seg.setDistanceThreshold(0.02);// 距离阈值 单位m。距离阈值决定了点被认为是局内点时必须满足的条件//seg.setDistanceThreshold(0.15);// 距离阈值 单位m。距离阈值决定了点被认为是局内点时必须满足的条件//距离阈值表示点到估计模型的距离最大值。seg.setInputCloud(cloud);//输入点云seg.segment(*inliers, *coefficients);//实现分割,并存储分割结果到点集合inliers及存储平面模型系数coefficientsif (inliers->indices.size() == 0){PCL_ERROR("Could not estimate a planar model for the given dataset.");return (-1);}//***********************************************************************//-----------输出平面模型的系数 a,b,c,d-----------cout << "Model coefficients: " << coefficients->values[0] << " "<< coefficients->values[1] << " "<< coefficients->values[2] << " "<< coefficients->values[3] << endl;cout << "Model inliers: " << inliers->indices.size() << endl;//***********************************************************************// 提取地面pcl::ExtractIndices<pcl::PointXYZ> extract;extract.setInputCloud(cloud);extract.setIndices(inliers);extract.filter(*cloud_filtered);cout << "Ground cloud after filtering: " << endl;cout << *cloud_filtered << std::endl;pcl::PCDWriter writer;writer.write<pcl::PointXYZ>("3dpoints_ground.pcd", *cloud_filtered, false);// 提取除地面外的物体extract.setNegative(true);extract.filter(*cloud_filtered);cout << "Object cloud after filtering: " << endl;cout << *cloud_filtered << endl;//writer.write<pcl::PointXYZ>(".pcd", *cloud_filtered, false);// 点云可视化boost::shared_ptr<pcl::visualization::PCLVisualizer>viewer0(new pcl::visualization::PCLVisualizer("显示点云"));//左边窗口显示输入的点云,右边的窗口显示分割后的点云int v1(0), v2(0);viewer0->createViewPort(0, 0, 0.5, 1, v1);viewer0->createViewPort(0.5, 0, 1, 1, v2);viewer0->setBackgroundColor(0, 0, 0, v1);viewer0->setBackgroundColor(0.3, 0.3, 0.3, v2);pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> color_in(cloud, 255, 0, 0);viewer0->addPointCloud<pcl::PointXYZ>(cloud, color_in, "cloud_in", v1);viewer0->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "cloud_in", v1);viewer0->addPointCloud<pcl::PointXYZ>(cloud_filtered, "cloud_out", v2);viewer0->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_COLOR, 0, 255, 0, "cloud_out", v2);viewer0->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "cloud_out", v2);while (!viewer0->wasStopped()){viewer0->spinOnce(100);boost::this_thread::sleep(boost::posix_time::microseconds(1000));}//***********************************************************************//超体聚类 float voxel_resolution = 0.01f;    // 设置体素大小,该设置决定底层八叉树的叶子尺寸float seed_resolution = 0.15f;    // 设置种子大小,该设置决定超体素的大小float color_importance = 0.0f;    // 设置颜色在距离测试公式中的权重,即颜色影响超体素分割结果的比重。 真实点云都是一个颜色,所以这个参数无作用float spatial_importance = 0.9f;  // 设置空间距离在距离测试公式中的权重,较高的值会构建非常规则的超体素,较低的值产生的体素会按照法线float normal_importance = 4.0f;   // 设置法向量的权重,即表面法向量影响超体素分割结果的比重。bool use_single_cam_transform = false;bool use_supervoxel_refinement = false;unsigned int k_factor = 0;//voxel_resolution is the resolution (in meters) of voxels used、seed_resolution is the average size (in meters) of resulting supervoxels  pcl::SupervoxelClustering<PointT> super(voxel_resolution, seed_resolution);super.setUseSingleCameraTransform(use_single_cam_transform);super.setInputCloud(cloud_filtered); //cloud_filteredsuper.setColorImportance(color_importance);//Set the importance of spatial distance for supervoxels.super.setSpatialImportance(spatial_importance);//Set the importance of scalar normal product for supervoxels. super.setNormalImportance(normal_importance);std::map<uint32_t, pcl::Supervoxel<PointT>::Ptr> supervoxel_clusters;super.extract(supervoxel_clusters);std::multimap<uint32_t, uint32_t> supervoxel_adjacency;super.getSupervoxelAdjacency(supervoxel_adjacency);pcl::PointCloud<pcl::PointNormal>::Ptr sv_centroid_normal_cloud = pcl::SupervoxelClustering<PointT>::makeSupervoxelNormalCloud(supervoxel_clusters);cout << "超体素分割的体素个数为:" << supervoxel_clusters.size() << endl;// 获取点云对应的超体素分割标签pcl::PointCloud<pcl::PointXYZL>::Ptr supervoxel_cloud = super.getLabeledCloud();pcl::visualization::PCLVisualizer::Ptr viewer1(new pcl::visualization::PCLVisualizer("VCCS"));viewer1->setWindowName("超体素分割");viewer1->addPointCloud(supervoxel_cloud, "超体素分割");viewer1->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "超体素分割");viewer1->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_OPACITY, 0.5, "超体素分割");//-----------------------------------------获得体素点云的邻接单元----------------------------------------------multimap<uint32_t, uint32_t>SupervoxelAdjacency;super.getSupervoxelAdjacency(SupervoxelAdjacency);for (auto label_itr = SupervoxelAdjacency.cbegin(); label_itr != SupervoxelAdjacency.cend();){uint32_t super_label = label_itr->first;//获取体素单元的标签pcl::Supervoxel<pcl::PointXYZ>::Ptr super_cloud = supervoxel_clusters.at(super_label);//把对应标签内的点云、体素质心、以及质心对应的法向量提取出来pcl::PointCloud<pcl::PointXYZRGBA> adjacent_supervoxel_centers;for (auto adjacent_itr = SupervoxelAdjacency.equal_range(super_label).first; adjacent_itr != SupervoxelAdjacency.equal_range(super_label).second; ++adjacent_itr){pcl::Supervoxel<pcl::PointXYZ>::Ptr neighbor_supervoxel = supervoxel_clusters.at(adjacent_itr->second);adjacent_supervoxel_centers.push_back(neighbor_supervoxel->centroid_);}std::stringstream ss;ss << "supervoxel_" << super_label;addSupervoxelConnectionsToViewer(super_cloud->centroid_, adjacent_supervoxel_centers, ss.str(), viewer1);label_itr = SupervoxelAdjacency.upper_bound(super_label);}// 等待直到可视化窗口关闭while (!viewer1->wasStopped()){viewer1->spinOnce(100);boost::this_thread::sleep(boost::posix_time::microseconds(1000));}//return 0;//***********************************************************************//LCCP分割float concavity_tolerance_threshold = 10;float smoothness_threshold = 0.8;uint32_t min_segment_size = 0;bool use_extended_convexity = false;bool use_sanity_criterion = false;pcl::LCCPSegmentation<PointT> lccp;lccp.setConcavityToleranceThreshold(concavity_tolerance_threshold);//CC效验beta值lccp.setSmoothnessCheck(true, voxel_resolution, seed_resolution, smoothness_threshold);lccp.setKFactor(k_factor);               //CC效验的k邻点lccp.setInputSupervoxels(supervoxel_clusters, supervoxel_adjacency);lccp.setMinSegmentSize(min_segment_size);//最小分割尺寸lccp.segment();pcl::PointCloud<pcl::PointXYZL>::Ptr sv_labeled_cloud = super.getLabeledCloud();pcl::PointCloud<pcl::PointXYZL>::Ptr lccp_labeled_cloud = sv_labeled_cloud->makeShared();lccp.relabelCloud(*lccp_labeled_cloud);SuperVoxelAdjacencyList sv_adjacency_list;lccp.getSVAdjacencyList(sv_adjacency_list);pcl::visualization::PCLVisualizer::Ptr viewer2(new pcl::visualization::PCLVisualizer("LCCP超体素分割"));viewer2->setWindowName("LCCP超体素分割");viewer2->addPointCloud(lccp_labeled_cloud, "LCCP超体素分割");viewer2->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "LCCP超体素分割");viewer2->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_OPACITY, 0.5, "LCCP超体素分割");// 等待直到可视化窗口关闭while (!viewer2->wasStopped()){viewer2->spinOnce(100);boost::this_thread::sleep(boost::posix_time::microseconds(1000));}return 0;}

三、实验结果

原数据
原数据
去除地面后
在这里插入图片描述
超体聚类过分割
在这里插入图片描述
LCCP分割
在这里插入图片描述

四、总结

从实验结果来看,LCCP算法在相似物体场景分割方面有着较好的表现,对于颜色类似但棱角分明的物体可使用该算法。

五、相关链接

[1]PCL-低层次视觉-点云分割(超体聚类)
[2]PCL_使用LCCP进行点云分割

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/875348.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

后端面试题日常练-day03 【Java基础】

题目 希望这些选择题能够帮助您进行后端面试的准备&#xff0c;答案在文末 在Java中&#xff0c;以下哪个关键字用于表示父类&#xff1f; a) super b) parent c) base d) root Java中的包&#xff08;package&#xff09;是用来做什么的&#xff1f; a) 组织和管理类 b) 定义…

ThinkPHP对接易联云打印

引入composer包 composer require yly-openapi/yly-openapi-sdk <?phpnamespace app\common\library;use app\admin\model\yp\Order; use App\Api\PrintService; use App\Config\YlyConfig; use App\Oauth\YlyOauthClient; use think\Cache; use think\Config;class Yly {…

DolphinScheduler学习

1.查看文档 点击访问&#xff1a;https://dolphinscheduler.apache.org/zh-cn/docs 我们可以看到相关的文档简介里有 介绍 DolphinScheduler是Apache DolphinScheduler 是一个分布式易扩展的可视化DAG工作流任务调度开源系统。适用于企业级场景&#xff0c;提供了一个可视化…

太原高校大学智能制造实验室数字孪生可视化系统平台建设项目验收

随着科技的不断进步&#xff0c;智能制造已经成为推动制造业转型升级的重要力量。太原高校大学智能制造实验室紧跟时代步伐&#xff0c;积极推进数字孪生可视化系统平台的建设&#xff0c;并于近日圆满完成了项目的验收工作。这一里程碑式的成果&#xff0c;不仅标志着实验室在…

uniapp安卓plus原生选择系统文件

uniapp安卓plus原生选择系统文件 效果&#xff1a; 组件代码&#xff1a; <template xlang"wxml" minapp"mpvue"><view></view> </template> <script>export default {name: file-manager,props: {},data() {return {is…

靶场实战 _ ATTCK 实战 Vulnstack 红队

环境配置 网络拓扑图 (仅供参考) 攻击机&#xff1a;kali ip:192.168.111.5靶机&#xff1a;web-centos 外网ip:192.168.111.10 内网ip:192.168.93.100web1-ubuntu ip: 192.168.93.120PC ip: 192.168.93.30win 2008 ip:192.168.93.20win 2012 ip:192.168.93.10 信息搜集 端口…

【C++】string类(下)

个人主页~ string类&#xff08;上&#xff09; string类 二、模拟实现string类1、头文件string.h2、常见构造3、容量函数4、访问及遍历5、类对象修改6、流插入流提取重载 二、模拟实现string类 今天我们来实现一下上篇文章中详细介绍过的接口 1、头文件string.h #pragma onc…

Redis的应用场景及类型

目录 一、Redis的应用场景 1、限流 2、分布式锁 3、点赞 4、消息队列 二、Redis类型的命令及用法 1、String类型 2、Hash类型 3、List类型 4、Set类型 5、Zset类型 6、Redis工具类 Redis使用缓存的目的就是提升读写性能 实际业务场景下&#xff0c;我们就可以把 Mys…

服务器选择租用还是托管?托管和租用哪个比较划算

在构建或扩展IT基础设施时&#xff0c;服务器作为关键组件&#xff0c;其选择方式——租用或托管&#xff0c;直接关系到企业的运营成本、灵活性、安全性及长期发展战略。本文将从技术、经济、安全等多个维度&#xff0c;深入解析这两种方案的优缺点&#xff0c;并探讨在何种情…

Dav_笔记11:SQL Tuning Overview-sql调优 之 1

Introduction to SQL Tuning SQL调优简介 SQL调优涉及以下基本步骤&#xff1a; ■通过查看系统中可用的过去SQL执行历史记录&#xff0c;识别负责大量应用程序工作负载和系统资源的高负载或顶级SQL语句 ■验证查询优化器为这些语句生成的执行计划是否合理执行 ■实施纠正…

力扣第三十一题——下一个排列

内容介绍 整数数组的一个 排列 就是将其所有成员以序列或线性顺序排列。 例如&#xff0c;arr [1,2,3] &#xff0c;以下这些都可以视作 arr 的排列&#xff1a;[1,2,3]、[1,3,2]、[3,1,2]、[2,3,1] 。 整数数组的 下一个排列 是指其整数的下一个字典序更大的排列。更正式地&…

redis详解--springboot整合redis

1. java连接redis 思考: 我们之前操作redis都是通过命令行的客户端来操作。 在开发时都是通过java项目操作redis.引入Redis依赖 <!--引入java连接redis的驱动--><dependency><groupId>redis.clients</groupId><artifactId>jedis</artifactI…

ThreadLocal面试三道题

针对ThreadLocal的面试题&#xff0c;我将按照由简单到困难的顺序给出三道题目&#xff0c;并附上参考答案的概要。 1. 简单题&#xff1a;请简述ThreadLocal是什么&#xff0c;以及它的主要作用。 参考答案&#xff1a; ThreadLocal是Java中的一个类&#xff0c;用于提供线…

力扣笔试题系列(一)

1、给你两个字符串 word1 和 word2 。请你从 word1 开始&#xff0c;通过交替添加字母来合并字符串。如果一个字符串比另一个字符串长&#xff0c;就将多出来的字母追加到合并后字符串的末尾。 char * mergeAlternately(char * word1, char * word2){int len1 strlen(word1);i…

C++ primer plus 第16章string 类和标准模板库, 无序关联容器(C++11)

C primer plus 第16章string 类和标准模板库, 无序关联容器(C11) C primer plus 第16章string 类和标准模板库, 无序关联容器(C11) 文章目录 C primer plus 第16章string 类和标准模板库, 无序关联容器(C11)16.4.5 无序关联容器(C11) 16.4.5 无序关联容器(C11) 无序关联容器是…

【常微分方程】

框架 常微分方程的概念一阶微分方程可变离分量齐次方程一阶线性微分方程可降阶的高阶微分方程二阶常系数齐次线性微分方程二阶常系数非齐次线性微分方程 讲解 【1】 常微分方程&#xff1a;是微分方程的特殊情况&#xff1b; 阶&#xff1a;是方程未知函数的最高阶导数的阶数&…

力扣138【随机链表的复制】

给你一个长度为 n 的链表&#xff0c;每个节点包含一个额外增加的随机指针 random &#xff0c;该指针可以指向链表中的任何节点或空节点。 构造这个链表的 深拷贝。 深拷贝应该正好由 n 个 全新 节点组成&#xff0c;其中每个新节点的值都设为其对应的原节点的值。新节点的 ne…

【.NET全栈】ASP.NET开发Web应用——ASP.NET数据绑定技术

文章目录 前言一、绑定技术基础1、单值绑定2、重复值绑定 二、数据源控件1、数据绑定的页面生存周期2、SqlDataSource3、使用参数过滤数据4、更新数据和并发处理5、编程执行SqlDataSource命令6、ObjectDataSource控件介绍7、创建业务对象类8、在ObiectDataSource中使用参数9、使…

06 ES6中的Map类型

ES6 中的 Map 是一种集合数据结构&#xff0c;与 Set 类似&#xff0c;但它是用来存储键值对的。Map 提供了更灵活的迭代和更广泛的键类型支持&#xff0c;与普通的对象相比&#xff0c;Map 的键可以是任何值&#xff0c;包括对象和函数。 以下是 Map 类型的一些关键特性和常用…

ElementUI,修改el-table中的数据,视图无法及时更新

需求&#xff1a;点击table表格中的“修改”之后&#xff0c;当前行变为可输入状态的行&#xff0c;点击“确定”后变为普通表格&#xff1b; 先贴上已经完美解决问题的代码 实现代码&#xff1a; <section><div style"display: flex;justify-content: space-b…