【Python - pcl】点云区域生长及最大区域可视化

RegionGrowing

Python - pcl求点云法线、建立kdtree、区域生长、可视化

例子

import pcl 
import pcl.pcl_visualization as viewer  #引入可视化库
import time

cloud0 = pcl.load("xxx.pcd")

# 求法线
ne=cloud0.make_NormalEstimation()
kdtree0=cloud04.make_kdtree()
# ne.set_KSearch(50)
ne.set_RadiusSearch(200.0)
# set_KSearch()和set_RadiusSearch()不要同时设置,不然计算法线结果为0
ne.set_SearchMethod(kdtree0)
normal0=ne.compute()

#区域生长
start = time.time()

rg=cloud0.make_RegionGrowing(searchRadius=400.0)# 同理,r和k只要填一个就行
rg.set_MaxClusterSize(100000)
rg.set_MinClusterSize(0)
rg.set_NumberOfNeighbours(200)
rg.set_InputNormals(normal0)
rg.set_SearchMethod(kdtree0)
rg.set_SmoothnessThreshold(2 / 180.0 * 3.14)
rg.set_CurvatureThreshold(0.5)
rg_result=rg.Extract()

end = time.time()
print("Execution Time: ", end - start)

# 取最大的num个区域
rg_list = sorted(rg_result,key = lambda i:len(i),reverse=True)  
arr=cloud0.to_array()

##渐变可视化最大的num个区域
vs=viewer.PCLVisualizering
vss1=viewer.PCLVisualizering()#初始化一个对象  
vs.SetBackgroundColor(vss1, 255, 255, 255)

num=10
for i in range(0, num):
    cloud_i=pcl.PointCloud(arr[rg_list[i]])
    visualcolor0 = viewer.PointCloudColorHandleringCustom(cloud_i, 255, 0, int(255/num*i))
    vs.AddPointCloud_ColorHandler(vss1,cloud_i,visualcolor0,id=b'cloud'+str(i).encode(),viewport=0)

while not vs.WasStopped(vss1):
    vs.Spin(vss1)


# 其他

# rg.get_CurvatureTestFlag() 
# rg.get_CurvatureThreshold()
# rg.get_MaxClusterSize()
# rg.get_MinClusterSize()
# rg.get_NumberOfNeighbours()
# rg.get_ResidualTestFlag()
# rg.get_ResidualThreshold()
# rg.get_SegmentFromPoint(index) # 获得点云中与第index个点处于相同区域的所有点的序号
# rg.get_SmoothModeFlag() 

说明文档

class RegionGrowing(builtins.object)
| Segmentation class for RegionGrowing
|
| Methods defined here:
|
| Extract(…)
| RegionGrowing.Extract(self)
|
| new(*args, **kwargs) from builtins.type
| Create and return a new object. See help(type) for accurate signature.
|
| get_CurvatureTestFlag(…)
| RegionGrowing.get_CurvatureTestFlag(self)
|
| get_CurvatureThreshold(…)
| RegionGrowing.get_CurvatureThreshold(self)
|
| get_MaxClusterSize(…)
| RegionGrowing.get_MaxClusterSize(self)
|
| get_MinClusterSize(…)
| RegionGrowing.get_MinClusterSize(self)
|
| get_NumberOfNeighbours(…)
| RegionGrowing.get_NumberOfNeighbours(self)
|
| get_ResidualTestFlag(…)
| RegionGrowing.get_ResidualTestFlag(self)
|
| get_ResidualThreshold(…)
| RegionGrowing.get_ResidualThreshold(self)
|
| get_SegmentFromPoint(…)
| RegionGrowing.get_SegmentFromPoint(self, int index)
|
| get_SmoothModeFlag(…)
| RegionGrowing.get_SmoothModeFlag(self)
|
| get_SmoothnessThreshold(…)
| RegionGrowing.get_SmoothnessThreshold(self)
|
| set_CurvatureTestFlag(…)
| RegionGrowing.set_CurvatureTestFlag(self, bool value)
|
| set_CurvatureThreshold(…)
| RegionGrowing.set_CurvatureThreshold(self, float curvature)
|
| set_InputNormals(…)
| RegionGrowing.set_InputNormals(self, PointCloud_Normal normals)
|
| set_MaxClusterSize(…)
| RegionGrowing.set_MaxClusterSize(self, int max)
|
| set_MinClusterSize(…)
| RegionGrowing.set_MinClusterSize(self, int min)
|
| set_NumberOfNeighbours(…)
| RegionGrowing.set_NumberOfNeighbours(self, int neighbour_number)
|
| set_ResidualTestFlag(…)
| RegionGrowing.set_ResidualTestFlag(self, bool value)
|
| set_ResidualThreshold(…)
| RegionGrowing.set_ResidualThreshold(self, float residual)
|
| set_SearchMethod(…)
| RegionGrowing.set_SearchMethod(self, KdTree kdtree)
|
| set_SmoothModeFlag(…)
| RegionGrowing.set_SmoothModeFlag(self, bool value)
|
| set_SmoothnessThreshold(…)
| RegionGrowing.set_SmoothnessThreshold(self, float theta)

你可能感兴趣的:(Python,PCL,可视化,python,自动驾驶,计算机视觉)