【PCL】(二十八)超体素聚类分割点云

(二十九)超体素聚类分割点云

论文:Voxel Cloud Connectivity Segmentation - Supervoxels for Point Clouds

supervoxel_clustering.cpp

#include <pcl/console/parse.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/segmentation/supervoxel_clustering.h>//VTK include needed for drawing graph lines
#include <vtkPolyLine.h>// Types
typedef pcl::PointXYZRGBA PointT;
typedef pcl::PointCloud<PointT> PointCloudT;
typedef pcl::PointNormal PointNT;
typedef pcl::PointCloud<PointNT> PointNCloudT;
typedef pcl::PointXYZL PointLT;
typedef pcl::PointCloud<PointLT> PointLCloudT;void addSupervoxelConnectionsToViewer (PointT &supervoxel_center,PointCloudT &adjacent_supervoxel_centers,std::string supervoxel_name,pcl::visualization::PCLVisualizer::Ptr & viewer);int main (int argc, char ** argv)
{if (argc < 2){pcl::console::print_error ("Syntax is: %s <pcd-file> \n ""--NT Dsables the single cloud transform \n""-v <voxel resolution>\n-s <seed resolution>\n""-c <color weight> \n-z <spatial weight> \n""-n <normal_weight>\n", argv[0]);return (1);}PointCloudT::Ptr cloud (new PointCloudT);pcl::console::print_highlight ("Loading point cloud...\n");if (pcl::io::loadPCDFile<PointT> (argv[1], *cloud)){pcl::console::print_error ("Error loading cloud file!\n");return (1);}/*--NT禁用单视图变换(仅影响有组织云)-v设置体素大小,决定基础八叉树结构的叶大小(以米为单位)-s设置种子大小,决定超体素的大小(以米为单位)-c设置颜色影响超体素的形状的权重-z设置空间项的权重-值越高,超体素越规则-n设置曲面法线影响超体素的形状的权重*/bool disable_transform = pcl::console::find_switch (argc, argv, "--NT");float voxel_resolution = 0.008f;bool voxel_res_specified = pcl::console::find_switch (argc, argv, "-v");if (voxel_res_specified)pcl::console::parse (argc, argv, "-v", voxel_resolution);float seed_resolution = 0.1f;bool seed_res_specified = pcl::console::find_switch (argc, argv, "-s");if (seed_res_specified)pcl::console::parse (argc, argv, "-s", seed_resolution);float color_importance = 0.2f;if (pcl::console::find_switch (argc, argv, "-c"))pcl::console::parse (argc, argv, "-c", color_importance);float spatial_importance = 0.4f;if (pcl::console::find_switch (argc, argv, "-z"))pcl::console::parse (argc, argv, "-z", spatial_importance);float normal_importance = 1.0f;if (pcl::console::find_switch (argc, argv, "-n"))pcl::console::parse (argc, argv, "-n", normal_importance);// 超体素聚类pcl::SupervoxelClustering<PointT> super (voxel_resolution, seed_resolution);if (disable_transform) // 如果收入是有组织的云,而该云的相机坐标不在(0,0,0)且深度不在正Z,则必须将use_transform设置为falsesuper.setUseSingleCameraTransform (false); super.setInputCloud (cloud);super.setColorImportance (color_importance);super.setSpatialImportance (spatial_importance);super.setNormalImportance (normal_importance);std::map <std::uint32_t, pcl::Supervoxel<PointT>::Ptr > supervoxel_clusters;pcl::console::print_highlight ("Extracting supervoxels!\n");super.extract (supervoxel_clusters);pcl::console::print_info ("Found %d supervoxels\n", supervoxel_clusters.size ());// 超体素可视化pcl::visualization::PCLVisualizer::Ptr viewer (new pcl::visualization::PCLVisualizer ("3D Viewer"));viewer->setBackgroundColor (0, 0, 0);// voxel_centroid_cloud包含由体素质心组成的云PointCloudT::Ptr voxel_centroid_cloud = super.getVoxelCentroidCloud ();viewer->addPointCloud (voxel_centroid_cloud, "voxel centroids");viewer->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE,2.0, "voxel centroids");viewer->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_OPACITY,0.95, "voxel centroids");//labeled_voxel_cloud 是根据其超体素标签(随机颜色)着色的体素。PointLCloudT::Ptr labeled_voxel_cloud = super.getLabeledVoxelCloud ();viewer->addPointCloud (labeled_voxel_cloud, "labeled voxels");viewer->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_OPACITY,0.8, "labeled voxels");// sv_normal_cloud包含一个超体素法线云,PointNCloudT::Ptr sv_normal_cloud = super.makeSupervoxelNormalCloud (supervoxel_clusters);//We have this disabled so graph is easy to see, uncomment to see supervoxel normals//viewer->addPointCloudNormals<PointNormal> (sv_normal_cloud,1,0.05f, "supervoxel_normals");pcl::console::print_highlight ("Getting supervoxel adjacency\n");std::multimap<std::uint32_t, std::uint32_t> supervoxel_adjacency;super.getSupervoxelAdjacency (supervoxel_adjacency);//To make a graph of the supervoxel adjacency, we need to iterate through the supervoxel adjacency multimapfor (auto label_itr = supervoxel_adjacency.cbegin (); label_itr != supervoxel_adjacency.cend (); ){//First get the label  std::uint32_t supervoxel_label = label_itr->first;//Now get the supervoxel corresponding to the labelpcl::Supervoxel<PointT>::Ptr supervoxel = supervoxel_clusters.at (supervoxel_label);//Now we need to iterate through the adjacent supervoxels and make a point cloud of themPointCloudT adjacent_supervoxel_centers;for (auto adjacent_itr = supervoxel_adjacency.equal_range (supervoxel_label).first; adjacent_itr!=supervoxel_adjacency.equal_range (supervoxel_label).second; ++adjacent_itr){pcl::Supervoxel<PointT>::Ptr neighbor_supervoxel = supervoxel_clusters.at (adjacent_itr->second);adjacent_supervoxel_centers.push_back (neighbor_supervoxel->centroid_);}//Now we make a name for this polygonstd::stringstream ss;ss << "supervoxel_" << supervoxel_label;//This function is shown below, but is beyond the scope of this tutorial - basically it just generates a "star" polygon mesh from the points givenaddSupervoxelConnectionsToViewer (supervoxel->centroid_, adjacent_supervoxel_centers, ss.str (), viewer);//Move iterator forward to next labellabel_itr = supervoxel_adjacency.upper_bound (supervoxel_label);}while (!viewer->wasStopped ()){viewer->spinOnce (100);}return (0);}void  addSupervoxelConnectionsToViewer (PointT &supervoxel_center,PointCloudT &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 ();//Iterate through all adjacent points, and add a center point to adjacent point pairfor (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);}// Create a polydata to store everything invtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New ();// Add the points to the datasetpolyData->SetPoints (points);polyLine->GetPointIds  ()->SetNumberOfIds(points->GetNumberOfPoints ());for(unsigned int i = 0; i < points->GetNumberOfPoints (); i++)polyLine->GetPointIds ()->SetId (i,i);cells->InsertNextCell (polyLine);// Add the lines to the datasetpolyData->SetLines (cells);viewer->addModelFromPolyData (polyData,supervoxel_name);
}
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)project(supervoxel_clustering)find_package(PCL 1.8 REQUIRED)include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})add_executable (supervoxel_clustering supervoxel_clustering.cpp)
target_link_libraries (supervoxel_clustering ${PCL_LIBRARIES})

数据样例

编译并运行:

./supervoxel_clustering milk_cartoon_all_small_clorox.pcd --NT -s 0.47

在这里插入图片描述

./supervoxel_clustering milk_cartoon_all_small_clorox.pcd --NT -s 0.1

在这里插入图片描述

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

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

相关文章

重启 explorer 进程的正确做法(二)

重启资源管理器进程的方法不唯一&#xff0c;但长期以来大家对实施方法用的不到位。 在上一篇中我认为&#xff1a;“我们往往使用 TerminateProcess 并传入 PID 和特殊结束代码 1 或者 taskkill /f /im 等方法重启资源管理器( explorer.exe )&#xff0c;其实这是不正确的。我…

21 卷积层里的多输入多输出通道【李沐动手学深度学习v2课程笔记】

目录 1. 多输入输出通道&相应代码实现 1.1 多输入 1.2 多输出 1.3 1x1 卷积层 1.4 小结 1. 多输入输出通道&相应代码实现 1.1 多输入 为了加深理解&#xff0c;我们实现一下多输入通道互相关运算。 简而言之&#xff0c;我们所做的就是对每个通道执行互相关操作&a…

CentOS 8启动流程

一、BIOS与UEFI BIOS Basic Input Output System的缩写&#xff0c;翻译过来就是“基本输入输出系统”&#xff0c;是一种业界标准的固件接口&#xff0c;第一次出现在1975年&#xff0c;是计算机启动时加载的第一个程序&#xff0c;主要功能是检测和设置计算机硬件&#xff…

题目:泡澡(蓝桥OJ 3898)

问题描述&#xff1a; 解题思路&#xff1a; 图解&#xff1a;&#xff08;以题目样例为例子&#xff09; 注意点&#xff1a;题目的W是每分钟最大出水量&#xff0c;因此有一分钟的用水量大于出水量则不通过。 补充&#xff1a;差分一般用于对一段区间每个元素加相同值&#x…

JZ76 删除链表中重复的结点

/*public class ListNode {int val;ListNode next null;ListNode(int val) {this.val val;} } */import java.util.*; public class Solution {public ListNode deleteDuplication(ListNode pHead) {//初步想想法&#xff1a; 弄一个hashmap 然后进行key存储起来。然后 如果存…

PHP将PDF转成多个PNG文件

1. 安装Imagick之前&#xff0c;您需要确保已安装PHP。如果您尚未安装PHP&#xff0c;请运行以下命令安装PHP及其常用扩展&#xff1a; sudo apt install php php-cli php-imagick 2. 安装Imagick PHP扩展&#xff1a; sudo apt install php-imagick 3.安装后&#xff0c;您…

python 查询json文件的某一行并 替换json 键值字符串右边的内容

在Python中处理JSON文件时&#xff0c;通常不需要按照行来查询和替换内容&#xff0c;因为JSON数据结构是键值对组成的&#xff0c;并且不以“行”为单位。你可以直接读取整个JSON文件&#xff0c;解析成字典对象&#xff0c;然后根据键名查找并修改对应的值。 以下是一个示例…

hibernate查询时会无限循环,然后报错:Exception in thread “main“ java.lang.StackOverflowError

遇到的情况有&#xff1a; 1、建表对应的时候“意外”添加了索引。解决&#xff1a;需要把索引删掉 2、打印查询到的单个实体信息时&#xff0c;使用了toString()方法。解决&#xff1a;不用就行了 3、多对多映射&#xff0c;查询到的整个实体集合时&#xff0c;直接打印这个…

web前端框架

目前比较火热的几门框架: React React是由Facebook(脸书)开发和创建的开源框架。React 用于开发丰富的用户界面&#xff0c;特别是当您需要构建单页应用程序时。它是最强大的前端框架。 弊端: 您不具备 JavaScript 的实践知识&#xff0c;则建议不要使用 React。同样&#x…

2024 年广东省职业院校技能大赛(高职组) “云计算应用”赛项样题①

2024 年广东省职业院校技能大赛&#xff08;高职组&#xff09; “云计算应用”赛项样题① 模块一 私有云&#xff08;50 分&#xff09;任务 1 私有云服务搭建&#xff08;10 分&#xff09;任务 2 私有云服务运维&#xff08;25 分&#xff09;任务 3 私有云运维开发&#xf…

人工智能(AI)领域最流行的八大算法概括

人工智能&#xff08;AI&#xff09;领域最流行的八大算法概括&#xff01; 1. 卷积神经网络&#xff08;CNN&#xff0c;Convolutional Neural Network&#xff09; 2. 图神经网络&#xff08;GNN&#xff0c;Graph Neural Network&#xff09; 3. 循环神经网络&#xff08;RN…

蓝桥杯第一天

这题就是典型的位数贡献大于数量贡献&#xff0c; 1花的火柴更少&#xff0c;所以尽量用完10个1&#xff0c;然后其实就是简单的背包问题尽量拿最多的物品&#xff08;数字&#xff09;&#xff0c;限重为300&#xff0c;各物品&#xff08;数字&#xff09;的重量即为所需火柴…

vue2的常用指令

什么是vue的内置指令 内置指令的一些新颖而有吸引力的用法&#xff0c;可以让您在开发中能加速开发效率,降低维护成本。 v-bind和v-model v-bind&#xff1a; 使用 v-bind 可以动态地绑定一个或多个特性&#xff0c;或者一个组件 prop 到表达式。可以使用简化语法 : 来代替 …

php文件操作

一、文件读取的5种方法 1&#xff0c;file_get_contents: 将整个文件读入一个字符串 file_get_contents( string $filename, bool $use_include_path false, ?resource $context null, int $offset 0, ?int $length null ): string|false 可以读取本地的文件也可以用来打…

Python语言元素之变量

程序是指令的集合&#xff0c;写程序就是用指令控制计算机做我们想让它做的事情。那么&#xff0c;为什么要用Python语言来写程序呢&#xff1f;因为Python语言简单优雅&#xff0c;相比C、C、Java这样的编程语言&#xff0c;Python对初学者更加友好。 一、一些计算机常识 在…

【Apache的安装与目录结构】讲解

Apache的安装与目录结构 0. 前言1. 安装Apache1.1 在Ubuntu/Debian上安装Apache1.2 在CentOS/Red Hat/Fedora上安装Apache1.3 在Windows上安装Apache1.4 在Mac OS X上安装Apache 2. Apache目录结构 0. 前言 Apache HTTP Server&#xff0c;简称Apache&#xff0c;是一个开源的…

储能系统--户用储能欧洲市场(三)

五、户用市场地域分析 2022年以来&#xff0c;全球能源供需格局进入调整阶段&#xff0c;越来越多的国家将储能列为加速其清洁能源转型的必选项。根据中关村储能产业技术联盟 &#xff08;CNESA&#xff09;数据&#xff0c;2022年全球新增投运电力储能项目装机规模30.7GW&…

删除 PostgresSql 数据库 报错:有 N 个其它会话正在使用数据库 的解决方案

说明此时有两个客户端在连接此数据库&#xff0c;此时不能删除数据库。 如果确定要强制删除此数据库&#xff0c;那么执行如下命令&#xff1a; SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE datname‘VolteAna3G’ AND pid<>pg_ba…

吴恩达机器学习笔记十六 如何debug一个学习算法 模型评估 模型选择和训练 交叉验证测试集

如果算法预测出的结果不太好&#xff0c;可以考虑以下几个方面&#xff1a; 获得更多的训练样本 采用更少的特征 尝试获取更多的特征 增加多项式特征 增大或减小 λ 模型评估(evaluate model) 例如房价预测&#xff0c;用五个数据训练出的模型能很好的拟合这几个数据&am…

Java观察者模式源码剖析及使用场景

观察者模式 一、原理及通俗理解二、股票项目中使用三、Spring框架中使用观察者模式四、总结优缺点以及使用经验一、优点二、缺点三、使用经验 一、原理及通俗理解 观察者模式是一种行为设计模式&#xff0c;它定义了对象之间的一对多依赖关系&#xff0c;使得一个对象的状态发…