当前位置: 首页 > news >正文

【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

在这里插入图片描述

相关文章:

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

&#xff08;二十九&#xff09;点云超体素分割 论文&#xff1a;Voxel Cloud Connectivity Segmentation - Supervoxels for Point Clouds supervoxel_clustering.cpp #include <pcl/console/parse.h> #include <pcl/point_cloud.h> #include <pcl/point_ty…...

Socket通信Demo(Unity客户端和C#)

Socket通信基本流程 首先要启动服务器创建Socket&#xff0c;然后要绑定服务器的一个端口这样客户端通过服务器IP端口号就能连接到服务器了服务器接下来会设置监听队列&#xff0c;监听并等待要连接到它的客户端客户端在服务器启动之后也建立自己的Socket&#xff0c;然后使用…...

Lucene 自定义词库

import org.apache.lucene.analysis.hunspell.Dictionary; import org.apache.lucene.analysis.hunspell.HunspellStemFilter; import...

【LeetCode热题100】73. 矩阵置零(矩阵)

一.题目要求 给定一个 m x n 的矩阵&#xff0c;如果一个元素为 0 &#xff0c;则将其所在行和列的所有元素都设为 0 。请使用 原地 算法。 二.题目难度 中等 三.输入样例 示例 1&#xff1a; 输入&#xff1a;matrix [[1,1,1],[1,0,1],[1,1,1]] 输出&#xff1a;[[1,0…...

使用Barrier共享鼠标键盘,通过macos控制ubuntu系统

之前文章写过如何使用barrrier通过windows系统控制ubuntu系统&#xff0c;该文章将详细介绍如何使用barrier通过macos系统控制ubuntu系统 一、macOS安装barrier macOS版本barrier链接 1、双击点开安装包 2、将安装包里的barrier拷贝到macOS的达达->应用程序中 3、在达达…...

c++:类和对象中:拷贝构造和赋值运算符重载详解

c:类和对象 构造函数和析构函数详解 文章目录 c:类和对象构造函数和析构函数详解 前言一、拷贝构造怎么写拷贝构造1.拷贝构造也是构造函数的一种,构造函数没有值.所以拷贝构造也没有返回值**2.拷贝构造只有一个形参,正常这个形参是自定义类型对象的引用.3. 如果我们没有显示写…...

Day33:安全开发-JavaEE应用SQL预编译Filter过滤器Listener监听器访问控制

目录 JavaEE-预编译-SQL JavaEE-过滤器-Filter JavaEE-监听器-Listen 思维导图 Java知识点 功能&#xff1a;数据库操作&#xff0c;文件操作&#xff0c;序列化数据&#xff0c;身份验证&#xff0c;框架开发&#xff0c;第三方库使用等. 框架库&#xff1a;MyBatis&#…...

Log4j如何支持多线程环境?你如何优化Log4j的性能?

Log4j如何支持多线程环境&#xff1f; Log4j 通过其内部设计来支持多线程环境&#xff0c;确保在多线程应用程序中能够安全地使用。以下是 Log4j 支持多线程环境的一些关键方面&#xff1a; 线程安全性&#xff1a; Log4j 的 Logger 类和 Appender 类都是设计为线程安全的。这…...

golang sync.Pool 指针数据覆盖问题

场景 1. sync.Pool设置 var stringPool sync.Pool{New: func() any {return new([]string)}, }func NewString() *[]string {v : stringPool.Get().(*[]string)return v }func PutString(s *[]string) {if s nil {return}if cap(*s) > 2048 {s nil} else {*s (*s)[:0]…...

VUE+内置iframe传值失效问题解决

起因&#xff1a; 公司业务需要计算建筑物截收面积&#xff0c;然后我采用的是openCV来计算&#xff0c;在vue内部引用不了&#xff0c;然后就采用了iframe原生html来完成&#xff1b;功能实现了我想让iframe和vue通信&#xff1b;然后用原有方式试了多次都失败了&#xff0c;i…...

Day31:安全开发-JS应用WebPack打包器第三方库JQuery安装使用安全检测

目录 打包器-WebPack-使用&安全 第三方库-JQuery-使用&安全 思维导图 JS知识点&#xff1a; 功能&#xff1a;登录验证&#xff0c;文件操作&#xff0c;SQL操作&#xff0c;云应用接入&#xff0c;框架开发&#xff0c;打包器使用等 技术&#xff1a;原生开发&…...

Go Zero微服务个人探究之路(十六)回顾api服务和rpc服务的本质

目录 前言 正文 API&#xff08;Application Programming Interface&#xff09; RPC&#xff08;Remote Procedure Call&#xff09; API 与 RPC 的关系 分布式部署 API 和 RPC 结语 前言 go-zero 是一个基于 Go 语言的微服务框架&#xff0c;它提供了一套简洁的编程模…...

基于YOLOv8/YOLOv7/YOLOv6/YOLOv5的夜间车辆检测系统(深度学习代码+UI界面+训练数据集)

摘要&#xff1a;开发夜间车辆检测系统对于自动驾驶技术具有关键作用。本篇博客详细介绍了如何运用深度学习构建一个夜间车辆检测系统&#xff0c;并提供了完整的实现代码。该系统基于强大的YOLOv8算法&#xff0c;并对比了YOLOv7、YOLOv6、YOLOv5&#xff0c;展示了不同模型间…...

Spring体系架构

目录 核心容器(Core Container) 数据访问/集成(Data Access/Integration) Web开发(Web)...

【PLC】现场总线和工业以太网汇总

1、 现场总线 1.1 什么是现场总线 1&#xff09;非专业描述&#xff1a; 如下图&#xff1a;“人机界面”一般通过以太网连接“控制器(PLC)”&#xff0c;“控制器(PLC)”通过 “现场总线”和现场设备连接。 2&#xff09;专业描述&#xff08;维基百科&#xff09; 现场总线…...

【吊打面试官系列】Java虚拟机JVM篇 - 关于JVM分析

大家好&#xff0c;我是锋哥。今天分享关于JVM分析的JVM面试题&#xff0c;希望对大家有帮助&#xff1b; 查看JVM进程号的命令是什么? 可以使用 ps ‐ef 和 jps ‐v 等等。 怎么查看剩余内存? 比如&#xff1a; free ‐m, free ‐h, top 命令等等。 1000道 互联网大厂Jav…...

Mysql锁与MVCC

文章目录 Mysql锁的类型锁使用MVCC快照读和当前读读视图【Read View】串行化的解决 exlpain字段解析ACID的原理日志引擎整合SpringBoot博客记录 Mysql锁的类型 MySQL中有哪些锁&#xff1a; 乐观锁&#xff08;Optimistic Locking&#xff09;&#xff1a;假设并发操作时不会发…...

rancher是什么

Rancher Labs是制作Rancher的公司。Rancher Labs成立于2014年&#xff0c;是一家专注于企业级容器管理软件的公司。它的产品设计旨在简化在分布式环境中部署和管理容器的过程&#xff0c;帮助企业轻松地采用容器技术和Kubernetes。Rancher Labs提供的Rancher平台支持Docker容器…...

阿里云服务器安全狗免费使用多引擎智能查杀引擎

云服务器具有按量付费、降低综合成本等诸多优势&#xff0c;受到很多企业的欢迎。 因此&#xff0c;目前使用的云服务器越来越多。 阿里云是目前云服务器中最具影响力的品牌&#xff0c;因此选择阿里云服务器的用户数量也是最多的。 那么阿里云服务器需要安装杀毒软件吗&#x…...

使用rust实现九九乘法表

rust目前拥有接近c/c的运行速度以及更快的编码支持&#xff0c;所以是很值得学习得一门语言。rust的语法及设计理念与其他的语言也有许多的不同之处。比如其特有的所有权属性。可以让开发者快速的开发出高效的运行程序。对于内存的管理也有极好的管理方案。 在这里使用rust语言…...

长江经济带综合矢量数据集|含长江+黄河+胡焕庸线+110城|WGS84坐标|SHP格式|

&#x1f50d; 数据简介 本数据集整合 长江干流、黄河干流、胡焕庸线&#xff08;黑河—腾冲线&#xff09; 以及 长江经济带110个核心城市 的权威边界与中心点&#xff0c;统一采用 WGS84地理坐标系&#xff08;EPSG:4326&#xff09;&#xff0c;格式为标准 Shapefile&#x…...

ADS1299心电图采集实战:从寄存器配置到数据解析全流程

ADS1299心电图采集实战&#xff1a;从寄存器配置到数据解析全流程 在医疗电子领域&#xff0c;高精度生物电信号采集是心电图(ECG)设备的核心技术挑战。德州仪器(TI)的ADS1299系列模数转换器以其优异的噪声性能和灵活的配置选项&#xff0c;成为专业级心电监测设备的首选方案。…...

告别Transformer依赖:用SegNeXt的MSCA模块,在ADE20K上轻松提升2% mIoU

SegNeXt实战&#xff1a;用MSCA模块在语义分割中实现轻量高效突破 语义分割领域近年来被Transformer架构主导&#xff0c;但计算成本高、调参复杂等问题一直困扰着工程师们。今天我们要探讨的SegNeXt&#xff0c;通过创新的多尺度卷积注意力&#xff08;MSCA&#xff09;模块&a…...

云容笔谈·东方红颜影像生成系统数据库课程设计选题:AI绘画作品管理平台

云容笔谈东方红颜影像生成系统数据库课程设计选题&#xff1a;AI绘画作品管理平台 最近几年&#xff0c;AI绘画技术发展得特别快&#xff0c;很多同学都想上手试试&#xff0c;生成的作品也越来越多。但不知道你有没有遇到过这样的烦恼&#xff1a;生成的图片一多&#xff0c;…...

低配置linux服务器基础优化

以2核1.5G&#xff0c;60G系统盘40G数据盘为例。发现虚拟内存只有1Groothlvps:~# free -htotal used free shared buff/cache available Mem: 1.3Gi 298Mi 1.1Gi 3.5Mi 92Mi 1.0Gi Swap: 974Mi …...

相机传感器尺寸与光圈F值的实战解析:如何选择最佳组合

1. 相机传感器尺寸&#xff1a;从参数到实际画质的影响 每次看到相机参数表里写着"1英寸传感器"或"1/2.3英寸CMOS"时&#xff0c;你是不是也疑惑过这些数字到底代表什么&#xff1f;我刚开始接触摄影时&#xff0c;曾经以为1英寸传感器就是对角线25.4mm&am…...

Qwen3-VL:30B部署常见问题解决:Web空白页、API连接超时、模型加载失败全解析

Qwen3-VL:30B部署常见问题解决&#xff1a;Web空白页、API连接超时、模型加载失败全解析 在上一篇教程《星图平台快速搭建 Clawdbot&#xff1a;私有化本地 Qwen3-VL:30B 并接入飞书》中&#xff0c;我们成功在星图AI云平台上部署了强大的多模态大模型Qwen3-VL:30B&#xff0c…...

基于VMware搭建HY-Motion 1.0多机训练集群

基于VMware搭建HY-Motion 1.0多机训练集群 想自己动手训练一个像HY-Motion 1.0这样能“一句话生成3D动画”的大模型&#xff0c;但被动辄几十张显卡的硬件需求吓退了&#xff1f;别急&#xff0c;今天咱们就来聊聊一个“曲线救国”的妙招&#xff1a;用你手头的普通电脑&#…...

GigaWorld-Policy——以动作为中心的世界–动作模型

前言// 待更第一部分 GigaWorld-Policy: An Efficient Action-CenteredWorld–Action Model1.1 引言与相关工作1.1.1 引言如原论文所说&#xff0c;近期&#xff0c;一些工作(Cen 等&#xff0c;2025&#xff1b;Chang 等&#xff0c;2025&#xff1b;Ni等&#xff0c;2025&…...

拆解液晶面板供电:用GH6121AC实现120mA双路输出的5个关键技巧

拆解液晶面板供电&#xff1a;用GH6121AC实现120mA双路输出的5个关键技巧 液晶面板的稳定供电是显示设备可靠运行的基础&#xff0c;而GH6121AC作为一款专为中小尺寸液晶面板优化的电源管理芯片&#xff0c;其双路120mA输出能力在3.3V系统中表现尤为突出。本文将深入剖析五个工…...