当前位置:网站首页>[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 .’
边栏推荐
- [Blue Bridge Cup training 100 questions] scratch digital calculation Blue Bridge Cup competition special prediction programming question collective training simulation exercise question No. 16
- Online JSON to plaintext tool
- Zero foundation self-study SQL course | complete collection of date functions in SQL
- 居家办公竟比去公司上班还累?
- Const keyword and its function (usage), detailed explanation of C language const
- vivado 如何添加时序约束
- How vivado adds timing constraints
- [PCL self study: segmentation4] point cloud segmentation based on Min cut
- 圖的存儲結構
- Windows环境下的ELK——Logstash+Mysql(4)
猜你喜欢

Excel print settings public header

ClickOnce error deploying ClickOnce application - the reference in the manifest does not match the identity of the downloaded assembly

Storage structure of graph

Detect objects and transfer images through mqtt

Swing UI container (I)

Summary of solutions to cross system data consistency problems
![[sword finger offer] 47 Maximum value of gifts](/img/bc/1aff1223b1672c4089151dc56c4d4e.png)
[sword finger offer] 47 Maximum value of gifts

golang - new和make的区别

撰写外文时怎样引用中文文献?

Discuz small fish game wind shadow legend business gbk+utf8 version template /dz game website template
随机推荐
Teach you how to transplant tinyriscv to FPGA
Windows环境下的ELK——Logstash+Mysql(4)
Usage of vivado vio IP
电子科大(申恒涛团队)&京东AI(梅涛团队)提出用于视频问答的结构化双流注意网络,性能SOTA!优于基于双视频表示的方法!
CUDA error:out of memory caused by insufficient video memory of 6G graphics card
如何找到外文文献对应的中文文献?
How vivado adds timing constraints
Cornernet understands from simple to profound
撰写外文时怎样引用中文文献?
clickonce 部署ClickOnce应用程序时出错-清单中的引用与下载的程序集的标识不匹配
Started a natural language model bloom
c语言字符指针、字符串初始化问题
Golang - the difference between new and make
捷码赋能案例:湖南天辰产研实力迅速提升!实战玩转智慧楼宇/工地等项目
图的存储结构
webserver流程图——搞懂webserver各模块间调用关系
The National University of Singapore 𞓜 uses model free reinforcement learning to evaluate the energy efficiency of the energy efficiency data center
EXCEL 打印设置公共表头
使用cef3开发的浏览器不支持flash问题的解决
Feign implements path escape through custom annotations