文章目录

  • 1.VS代码实现
  • 2.点云数据
  • 3.结果

1.VS代码实现

声明:代可以在vs2019+pcl1.11.1上直接运行;由于没有RGBA数据,在demo点云文件上增加了RGBA信息,验证了代码的可行性。

#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>
#include <boost/make_shared.hpp>
#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> Pointvoid addSupervoxelConnectionsToViewer(PointT& supervoxel_center, PointCloudT& adjacent_supervoxel_centers,std::string supervoxel_name,boost::shared_ptr<pcl::visualization::PCLVisualizer>& 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 pairPointCloudT::iterator adjacent_itr = adjacent_supervoxel_centers.begin();for (; 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 datasetpolyLine->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);}bool superVoxelClustering()
{std::string cloudPath = "data/table_scene_lms400_sample.pcd";PointCloudT::Ptr cloud (new PointCloudT());pcl::PointCloud<pcl::PointXYZ>::Ptr cloudTmp(new pcl::PointCloud<pcl::PointXYZ>);pcl::console::print_highlight("Loading point cloud...\n");if (pcl::io::loadPCDFile<pcl::PointXYZ>("data/table_scene_lms400_sample.pcd", *cloudTmp)){return (1);}float minZ = 10000000.0, maxZ = -10000;for (int i = 0; i < 11000; i++){if (cloudTmp->at(i).z > maxZ){maxZ = cloudTmp->at(i).z;}if (cloudTmp->at(i).z < minZ){minZ = cloudTmp->at(i).z;}}cloud->resize(11000);for (int i = 0; i < 11000; i++){cloud->at(i).x = cloudTmp->at(i).x;cloud->at(i).y = cloudTmp->at(i).y;cloud->at(i).z = cloudTmp->at(i).z;cloud->at(i).r = (cloudTmp->at(i).z - minZ) / (maxZ - minZ)*255.0;cloud->at(i).g = 0;cloud->at(i).b = 0;cloud->at(i).a = (cloudTmp->at(i).z - minZ) / (maxZ - minZ) * 255.0;}float voxel_resolution = 0.008f;float seed_resolution = 0.1f;float color_importance = 0.2f;float spatial_importance = 0.4f;float normal_importance = 1.0f;bool use_tranform = true;
pcl::SupervoxelClustering<PointT> super(voxel_resolution, seed_resolution);super.setInputCloud(cloud);super.setColorImportance(color_importance);super.setSpatialImportance(spatial_importance);super.setNormalImportance(normal_importance);std::map <uint32_t, pcl::Supervoxel<PointT>::Ptr > supervoxel_clusters;super.extract(supervoxel_clusters);
supervoxel_clusters.size());boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer(new pcl::visualization::PCLVisualizer("3D Viewer"));viewer->setBackgroundColor(0, 0, 0);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");PointCloudT::Ptr colored_voxel_cloud = super.getColoredCloud();viewer->addPointCloud(colored_voxel_cloud, "colored voxels");viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_OPACITY, 0.8, "colored voxels");PointNCloudT::Ptr sv_normal_cloud = super.makeSupervoxelNormalCloud(supervoxel_clusters);pcl::console::print_highlight("Getting supervoxel adjacency\n");std::multimap<uint32_t, uint32_t> supervoxel_adjacency;super.getSupervoxelAdjacency(supervoxel_adjacency);std::multimap<uint32_t, uint32_t>::iterator label_itr = supervoxel_adjacency.begin();for (; label_itr != supervoxel_adjacency.end(); ){uint32_t supervoxel_label = label_itr->first;//Now get the supervoxel corresponding to the labelpcl::Supervoxel<PointT>::Ptr supervoxel = supervoxel_clusters.at(supervoxel_label);PointCloudT adjacent_supervoxel_centers;std::multimap<uint32_t, uint32_t>::iterator adjacent_itr = supervoxel_adjacency.equal_range(supervoxel_label).first;for (; 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_);}std::stringstream ss;ss << "supervoxel_" << supervoxel_label;addSupervoxelConnectionsToViewer(supervoxel->centroid_, adjacent_supervoxel_centers, ss.str(), viewer);label_itr = supervoxel_adjacency.upper_bound(supervoxel_label);}while (!viewer->wasStopped()){viewer->spinOnce(100);}return true;
}

2.点云数据

3.结果


PCL超体素分割代码vs2019+pcl1.11.1实现相关推荐

  1. 超体素分割——分割块点云单独保存及遗漏点的处理

    根据上一篇博客介绍的超体素分割原理,在PCL中该功能以将其实现,并将其进行可视化.但是存在如下问题:(1)其将所有的块同时显示,对于很多其他应用,比如后续处理需要对每一块点单独进行操作,那么就需要将每 ...

  2. 基于机器学习的自适应超体素分割揭示了人脑中的躯体定位组织

    文章来源于微信公众号(茗创科技),欢迎有兴趣的朋友搜索关注 导读 除了在中央前回和中央后回的成熟的躯体组织外,目前强有力的证据表明躯体组织在感觉运动网络的其他区域也很明显.这就存在几个实验问题:感觉运 ...

  3. win10+vs2019+pcl1.11.0安装教程

    看pointnet论文的时候发现有点云的可视化,但里面的可视化好像是基于CAD做的,正好最近我在用c++处理一些点云数据,就想着怎么直接把点云显示出来,就找到了PCL库,与opencv类似,openc ...

  4. PCL——超体素(SuperVoxel)、超体聚类分割

  5. SILC 超像素分割代码

    详见:https://www.cnblogs.com/wangyong/p/8991465.html import math from skimage import io, color import ...

  6. VS2019++QT5.12.10+PCL1.11.1+VTK8.2.0+opencv(camke3.18.0)环境搭配及演示实例

    一.参考链接: 1.VS2019+QT5.12.10+PCL1.11.1+VTK8.2.0(cmake3.20.4)环境搭配_寒木休思的博客-CSDN博客 2.VS2019+PCL1.11.1+VTK ...

  7. CloudComparePCL 基于超体素的点云分割

    文章目录 一.原理概述 二.实现过程 三.实现效果 参考资料 一.原理概述 一般而言,孤立的点并没有什么意义,只有许多点组合在一起形成一种形状,这样才能对我们有所意义.二维图像处理领域中,很早就出现了 ...

  8. PCL中点云的超体素(SuperVoxel)

    各位小伙伴们,有没有发现PCL库中已经集成了太多我们想实现的算法或者功能呢?所以这里组织一下学习小组针对PCL库中实现的算法进行剖析与论文解读,所以希望更多的小伙伴们参与进来,我们一起吃透PCL,欢迎 ...

  9. SuperVoxel:PCL中点云的超体素

    点击上方"3D视觉工坊",选择"星标" 干货第一时间送达 标题:Voxel Cloud Connectivity Segmentation - Supervox ...

最新文章

  1. 从多维度解析神经科学中的视觉编码
  2. 程序计算机限制无法打开,由于一个软件限制策略的阻止,windows无法打开此程序...解决方案参考...
  3. 拖拖拽拽画JAVA报表?
  4. html四个标签,基本的 HTML 标签 - 四个实例
  5. Android的四大组件
  6. 生命周期结束,Spring Boot 1.x退役
  7. Azure 物联网开发者体验 7 月更新:边缘计算开发工具,ARM64 设备开发,VS Code 容器化开发工具...
  8. 马匹赛跑java_java模拟龟兔赛跑
  9. Python与数据库[2] - 关系对象映射/ORM[4] - sqlalchemy 的显式 ORM 访问方式
  10. DELL戴尔服务器RAID磁盘阵列默认识别更换后的硬盘
  11. linux fileinfo.so,Centos 下编译安装fileinfo扩展
  12. AndroidHttpCapture抓包工具
  13. Retina屏而被图处理
  14. SAP_ABAP 采购价格条件报表(改进版1)
  15. 猿创征文|我命由我,不由天
  16. 阿里云RDS数据库如何远程访问
  17. python-数据分析-pandas
  18. 1100 校庆(JAVA)
  19. BS客户端安全使用解决方案
  20. Android 序列化 ---- Parcelable原理分析

热门文章

  1. 用CentOS 7打造合适的科研环境 :zhuan
  2. 【渝粤教育】国家开放大学2018年春季 8644-21T汽车电子商务 参考试题
  3. UltraEdit14.00b 注册码
  4. 从威客到互联网进化论的五年历程
  5. VB计算MACD指标详细编码
  6. shellcode教程从新手到高手
  7. 初阶后的C++ 第七节 —— 多态
  8. 奥运金牌金镶玉到底值多少钱
  9. Netty 是什么?
  10. 戴森空气净化器php00使用,戴森空气净化器如何使用 戴森空气净化器使用方法介绍【图文】...