当前位置:网站首页>[PCL self study: Segmentation3] PCL based point cloud segmentation: region growth segmentation
[PCL self study: Segmentation3] PCL based point cloud segmentation: region growth segmentation
2022-06-27 23:47:00 【Stanford rabbit】
be based on PCL Point cloud region growth segmentation
One 、 What is regional growth segmentation
In this paper , We will learn how to use pcl:: regiongrow Class . The purpose of the algorithm is to classify points that are close enough in terms of smoothness constraints . therefore , The output of the algorithm is a set of clusters , Each cluster is a set of points , Is considered to be part of the same smooth surface . The work of this algorithm is based on the comparison of the angles between point normals .
Two 、 Analysis of the division principle of regional growth
Let's see how the algorithm works .
1. First , It classifies points according to their curvature values . The reason to do this is because this region grows from the point where the curvature is the smallest . This is because the point with the smallest curvature is located in a flat area ( Growing from the flattest region can reduce the total number of partitions ).
2. The selected point is added to a field named seeds( Growth seed set ) The collection of .
3. For each seed point , The algorithm finds its neighbors .
a. Each neighbor is calculated the angle between its normal and the normal of the current seed point . If the angle is less than the threshold , Then add the current point to the area where the current seed is located .
b. Then test the curvature value of each neighborhood . If the curvature is less than the threshold , Then add this point to the seed collection as a new seed .
c. Delete the current seed from the seed collection .
4. If the seed set becomes empty , This means that the algorithm expands the area , This process repeats iterations from the beginning , Until the seed set is empty .
3、 ... and 、 Region growth segmentation example code
#include <iostream>
#include <vector>
#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>
#include <pcl/search/search.h>
#include <pcl/search/kdtree.h>
#include <pcl/features/normal_3d.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/filters/filter_indices.h> // for pcl::removeNaNFromPointCloud
#include <pcl/segmentation/region_growing.h>
int
main ()
{
// Read point cloud pcd file
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
if ( pcl::io::loadPCDFile <pcl::PointXYZ> ("region_growing_tutorial.pcd", *cloud) == -1)
{
std::cout << "Cloud reading failed." << std::endl;
return (-1);
}
// Build search KD Trees
pcl::search::Search<pcl::PointXYZ>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZ>);
// Calculate the normal direction of the point cloud
pcl::PointCloud <pcl::Normal>::Ptr normals (new pcl::PointCloud <pcl::Normal>);
pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> normal_estimator;
normal_estimator.setSearchMethod (tree); // The search method is kd Treetop
normal_estimator.setInputCloud (cloud); // Fill in the point cloud
normal_estimator.setKSearch (50); // Set the search scope
normal_estimator.compute (*normals); // Save the law normals
pcl::IndicesPtr indices (new std::vector <int>);
pcl::removeNaNFromPointCloud(*cloud, *indices); // Indexing point clouds
pcl::RegionGrowing<pcl::PointXYZ, pcl::Normal> reg; // Regional growth
reg.setMinClusterSize (50); // Set the minimum number of collection points
reg.setMaxClusterSize (1000000); // Set the maximum number of collection points
reg.setSearchMethod (tree); // Set up kd Tree search method
reg.setNumberOfNeighbours (30); // Set the number of neighborhood searches per time ( Affect the calculation speed )
reg.setInputCloud (cloud); // Set the input point cloud
reg.setIndices (indices); // Set the input index
reg.setInputNormals (normals); // Set the input normal
reg.setSmoothnessThreshold (3.0 / 180.0 * M_PI); // Set the smoothness threshold ( radian )
reg.setCurvatureThreshold (1.0); // Set the curvature threshold
// A collection of categories And start calculating
std::vector <pcl::PointIndices> clusters;
reg.extract (clusters);
// A series of outputs
std::cout << "Number of clusters is equal to " << clusters.size () << std::endl;
std::cout << "First cluster has " << clusters[0].indices.size () << " points." << std::endl;
std::cout << "These are the indices of the points of the initial" <<
std::endl << "cloud that belong to the first cluster:" << std::endl;
std::size_t counter = 0;
while (counter < clusters[0].indices.size ())
{
std::cout << clusters[0].indices[counter] << ", ";
counter++;
if (counter % 10 == 0)
std::cout << std::endl;
}
std::cout << std::endl;
// Show the split point cloud , And give different colors
pcl::PointCloud <pcl::PointXYZRGB>::Ptr colored_cloud = reg.getColoredCloud ();
pcl::visualization::CloudViewer viewer ("Cluster viewer");
viewer.showCloud(colored_cloud);
while (!viewer.wasStopped ())
{
}
return (0);
}
The operation effect is as follows :
【 About bloggers 】
Stanford rabbit , male , Master of engineering, Tianjin University . Since graduation, I have been engaged in optical three-dimensional imaging and point cloud processing . Because the three-dimensional processing library used in work is the internal library of the company , Not universally applicable , So I learned to open source by myself PCL Library and its related mathematical knowledge for use . I would like to share the self-study process with you .
Bloggers lack of talent and knowledge , Not yet able to guide , If you have any questions, please leave a message in the comments section for everyone to discuss .’
边栏推荐
- Golang uses Mongo driver operation -- Query (array related)
- 获取基因有效长度的N种方法
- [PCL self study: pclvisualizer] point cloud visualization tool pclvisualizer
- 捷码赋能案例:湖南天辰产研实力迅速提升!实战玩转智慧楼宇/工地等项目
- 【蓝桥杯集训100题】scratch数字计算 蓝桥杯scratch比赛专项预测编程题 集训模拟练习题第16题
- How vivado adds timing constraints
- Windows环境下的ELK——Logstash+Mysql(4)
- 零基础自学SQL课程 | SQL基本函数大全
- 【tinyriscv verilator】分支移植到正点原子达芬奇开发板
- Google Earth Engine(GEE) 03-矢量数据类型
猜你喜欢

2022年PMP项目管理考试敏捷知识点(3)

打造南沙“强芯”,南沙首届IC Nansha大会召开

An analysis of C language functions

C# Winform 读取Resources图片
![[try to hack] kill evaluation](/img/93/e623e25dc4dec1f656227c7651577e.png)
[try to hack] kill evaluation

Zero foundation self-study SQL course | complete collection of date functions in SQL

Swing UI container (I)

Introduction to quantitative trading

Summary of solutions to cross system data consistency problems

webserver流程图——搞懂webserver各模块间调用关系
随机推荐
通过中金证券经理的开户二维码开股票账户安全吗?还是去证券公司开户安全?
Discuz small fish game wind shadow legend business gbk+utf8 version template /dz game website template
Realization of kaggle cat dog recognition by pytorch
小程序referer
第 2 章 集成 MP
Typora 1.2.5等版本下载
Swing UI container (I)
clickonce 部署ClickOnce应用程序时出错-清单中的引用与下载的程序集的标识不匹配
fiddler 监听不到接口怎么办
The National University of Singapore 𞓜 uses model free reinforcement learning to evaluate the energy efficiency of the energy efficiency data center
ICML 2022: UFRGS |作为最优策略转移基础的乐观线性支持和后继特征
Zero foundation self-study SQL course | case function
c语言之字符串数组
[Blue Bridge Cup training 100 questions] scratch digital calculation Blue Bridge Cup competition special prediction programming question collective training simulation exercise question No. 16
[PCL self study: pclvisualizer] point cloud visualization tool pclvisualizer
Swing UI——容器(一)
最新云开发微信余额充电器特效小程序源码
【PCL自学:Segmentation3】基于PCL的点云分割:区域增长分割
Feign通过自定义注解实现路径的转义
【微服务|Sentinel】sentinel数据持久化