PCL学习笔记(10)——PCL超体素VCCS算法

更新时间:2023-06-02 13:11:43 阅读: 评论:0

PCL学习笔记(10)——PCL超体素VCCS算法
超体(supervoxel)是⼀种集合,集合的元素是“体”。与体素滤波器中的体类似,其本质是⼀个个的⼩⽅块。与之前提到的所有分割⼿段不同,超体聚类的⽬的并不是分割出某种特定物体,其对点云实施过分割(over gmentation),将场景点云化成很多⼩块,并研究每个⼩块之间的关系。这种将更⼩单元合并的分割思路已经出现了有些年份了,在图像分割中,像素聚类形成超像素,以超像素关系来理解图像已经⼴为研究。本质上这种⽅法是对局部的⼀种总结,纹理,材质,颜⾊类似的部分会被⾃动的分割成⼀块,有利于后续识别⼯作。⽐如对⼈的识别,如果能将头发,⾯部,四肢,躯⼲分开,则能更好的对各种姿态,性别的⼈进⾏识别。
点云和图像不⼀样,其不存在像素邻接关系。所以,超体聚类之前,必须以⼋叉树对点云进⾏划分,获得不同点团之间的邻接关系。与图像相似点云的邻接关系也有很多,如⾯邻接,线邻接,点邻接。其具体解释如下图:
从右到左,6(⾯)、18(⾯、边)、26(⾯、边、顶点)邻接
基于超体聚类的点云分割,使⽤点邻接(蓝⾊)作为相邻判据。
VCCS是⼀种增量扩展的区域增长⽅法 极好的来⾃⼀组种⼦点的体素在分辨率为 R_ed 的⽹格上均匀分布在空间中。为了保持效
率,VCCS 不会全局搜索,⽽是只考虑种⼦中⼼ R_ed 内的点。此外,通过在每个种⼦周围建⽴⼀个⼩的搜索半径 R_arch 并移除没有⾜够的相邻体素连接到它们的种⼦来过滤掉被隔离的种⼦。
#include<pcl/console/par.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/gmentation/supervoxel_clustering.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,
boost::shared_ptr<pcl::visualization::PCLVisualizer>& viewer);
int
main(int argc,char** argv)
{
PointCloudT::Ptr cloud = boost::make_shared <PointCloudT>();
pcl::console::print_highlight("Loading \n");
if(pcl::io::loadPCDFile<PointT>("hengliang.pcd",*cloud))
{
pcl::console::print_error("Error loading cloud file!\n");
return(1);
}
cout <<"point size of input: "<< cloud->size()<< endl;
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::par(argc, argv,"-v", voxel_resolution);
float ed_resolution =0.1f;
bool ed_res_specified = pcl::console::find_switch(argc, argv,"-s");//设置种⼦⼤⼩,该设置决定超级体素的⼤⼩
if(ed_res_specified)
pcl::console::par(argc, argv,"-s", ed_resolution);
float color_importance =0.2f;
if(pcl::console::find_switch(argc, argv,"-c"))//设置颜⾊在距离测量公式中的权重
pcl::console::par(argc, argv,"-c", color_importance);
float spatial_importance =0.4f;
if(pcl::console::find_switch(argc, argv,"-z"))//设置空间距离在距离测量公式中的权重,此值越⼤超级体素越规则
pcl::console::par(argc, argv,"-z", spatial_importance);
float normal_importance =1.0f;
if(pcl::console::find_switch(argc, argv,"-n"))//设置法向量的权重,即表⾯法向量影响体素分割结果的⽐重
pcl::console::par(argc, argv,"-n", normal_importance);
// This is how to u supervoxels
pcl::SupervoxelClustering<PointT>super(voxel_resolution, ed_resolution);
if(disable_transform)
super.tUSingleCameraTransform(fal);
super.tInputCloud(cloud);//设置输⼊点云
super.tColorImportance(color_importance);//设置颜⾊空间距离权重
super.tSpatialImportance(spatial_importance);//设置物理位置空间距离权重
super.tNormalImportance(normal_importance);//设置法向量权重
std::map <uint32_t, pcl::Supervoxel<PointT>::Ptr > supervoxel_clusters;
//该单映射容器以标签为键值存储所有超体素
pcl::console::print_highlight("Extracting supervoxels!\n");
pcl::console::print_info("Found %d supervoxels\n", supervoxel_clusters.size());
boost::shared_ptr<pcl::visualization::PCLVisualizer>viewer(new pcl::visualization::PCLVisualizer("点云库PCL学习教程第⼆版-超体素分割")); viewer->tBackgroundColor(1,1,1);
PointCloudT::Ptr voxel_centroid_cloud = VoxelCentroidCloud();//voxel_centroid_cloud包含根据⼋叉树结构得到的体素质⼼
cout <<"voxel centroids: "<< voxel_centroid_cloud->size()<< endl;
if(0)
{//对于体素中⼼的可视化和保存,基本就是对原始数据的空间均匀下采样
viewer->addPointCloud<PointT>(voxel_centroid_cloud,"voxel centroids");
pcl::io::savePCDFile("voxel_centroids.pcd",*voxel_centroid_cloud);
viewer->tPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE,4,"voxel centroids");
viewer->tPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_OPACITY,0.5,"voxel centroids");
}
PointLCloudT::Ptr labeled_voxel_cloud = LabeledVoxelCloud();//labeled_voxel_cloud包含标签的点云数据,属于同⼀体素的点具有相同标签if(1)
{//超体素分割结果显⽰与保存
pcl::io::savePCDFile("result.pcd",*labeled_voxel_cloud);
射精有什么好处
viewer->addPointCloud(labeled_voxel_cloud,"labeled voxels");
cout <<"labeled voxels: "<< labeled_voxel_cloud->size()<< endl;
viewer->tPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE,3,"labeled voxels");
// viewer->tPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_OPACITY,0.8, "labeled voxels");
}
PointNCloudT::Ptr sv_normal_cloud = super.makeSupervoxelNormalCloud(supervoxel_clusters);//sv_normal_cloud包含超体素法向量的点云数据
春夏秋冬的你歌词//
if(0)//超体素对应的法线特征可视化
viewer->addPointCloudNormals<pcl::PointNormal>(sv_normal_cloud,1,0.05f,"supervoxel_normals");
pcl::console::print_highlight("Getting supervoxel adjacency\n");
std::multimap<uint32_t,uint32_t> supervoxel_adjacency;
cout <<"size of supervoxel_adjacency: "<< supervoxel_adjacency.size()<< endl;
//遍历多重映射容器构造邻接图
std::multimap<uint32_t,uint32_t>::iterator label_itr = supervoxel_adjacency.begin();
for(; label_itr != d();)
{
//获取标签值
uint32_t supervoxel_label = label_itr->first;
//根据标签索引到该超体素
pcl::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).cond;++adjacent_itr)
{
pcl::Supervoxel<PointT>::Ptr neighbor_supervoxel = supervoxel_clusters.at(adjacent_itr->cond);
adjacent_supervoxel_centers.push_back(neighbor_supervoxel->centroid_);
}
//
直尺用英语怎么说std::stringstream ss;
ss <<"supervoxel_"<< supervoxel_label;
//cout<<ss.str()<<endl;
//绘制该超体素与其相邻超体素⼦图
addSupervoxelConnectionsToViewer(supervoxel->centroid_, adjacent_supervoxel_centers, ss.str(), viewer);
//使迭代器指向下⼀个标签。
label_itr = supervoxel_adjacency.upper_bound(supervoxel_label);
}
while(!viewer->wasStopped())
{
viewer->spinOnce();
}
return(0);
}
void
addSupervoxelConnectionsToViewer(PointT &supervoxel_center,
PointCloudT &adjacent_supervoxel_centers,
std::string supervoxel_name,
boost::shared_ptr<pcl::visualization::PCLVisualizer>& viewer)
{
int i =0;
//Iterate through all adjacent points, and add a center point to adjacent point pair
烤蒜
PointCloudT::iterator adjacent_itr = adjacent_supervoxel_centers.begin();
for(; adjacent_itr != adjacent_d();++adjacent_itr)
{
std::stringstream ss;
程序管理器ss << supervoxel_name << i;
华尔街操盘手日记viewer->addLine(supervoxel_center,*adjacent_itr, ss.str());
viewer->tShapeRenderingProperties(pcl::visualization::PCL_VISUALIZER_LINE_WIDTH,3, ss.str());
viewer->tShapeRenderingProperties(pcl::visualization::PCL_VISUALIZER_COLOR,0,255,0, ss.str());
ss << supervoxel_name << i;
viewer->addSphere(supervoxel_center,0.008,0,0,255, ss.str());
viewer->tShapeRenderingProperties(pcl::visualization::PCL_VISUALIZER_SHADING, pcl::visualization::PCL_VISUALIZER_SHADING_GOURAUD, ss.st r());
//viewer->tShapeRenderingProperties(pcl::visualization::PCL_VISUALIZER_OPACITY,0.9,ss.str());
i++;
地形分析
}
}

本文发布于:2023-06-02 13:11:43,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/833496.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:体素   分割   邻接
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图