我有陆地激光扫描仪创建的森林图的激光雷达点云。我想在Python-PCL库中使用cylinder segmentation来检测掉落的粗糙木质碎片(死木)。我在1.3 m上方切出了点云,因此剩余的点云包含枯木以及茎和地面点的其余部分。
代码运行良好,但是会在点云的一部分上创建圆柱点,请参见附件
我需要帮助来改进代码,以便它可以在整个图中创建线段。 这是代码:
import pcl
cloud = pcl.load('input.pcd')
print(cloud.size)
fil = cloud.make_passthrough_filter()
fil.set_filter_field_name("z")
fil.set_filter_limits(0, 1.5)
cloud_filtered = fil.filter()
print(cloud_filtered.size)
seg = cloud_filtered.make_segmenter_normals(ksearch=50)
seg.set_optimize_coefficients(True)
seg.set_model_type(pcl.SACMODEL_NORMAL_PLANE)
seg.set_normal_distance_weight(0.1)
seg.set_method_type(pcl.SAC_RANSAC)
seg.set_max_iterations(100)
seg.set_distance_threshold(0.03)
indices, model = seg.segment()
print(model)
cloud_plane = cloud_filtered.extract(indices, negative=False)
pcl.save(cloud_plane, 'outputPlane.pcd')
cloud_cyl = cloud_filtered.extract(indices, negative=True)
seg = cloud_cyl.make_segmenter_normals(ksearch=50)
seg.set_optimize_coefficients(True)
seg.set_model_type(pcl.SACMODEL_CYLINDER)
seg.set_normal_distance_weight(0.1)
seg.set_method_type(pcl.SAC_RANSAC)
seg.set_max_iterations(10000)
seg.set_distance_threshold(0.99)
seg.set_radius_limits(0, 0.1)
indices, model = seg.segment()
print(model)
cloud_cylinder = cloud_cyl.extract(indices, negative=False)
pcl.save(cloud_cylinder, 'output_cylinder.pcd')