python-pcl,点云滤波,平面分割
程序员文章站
2024-03-25 10:37:10
...
用python-pcl对得到的点云数据进行滤波,平面分割等
github地址 https://github.com/strawlab/python-pcl example里面有许多例子可以参考
1.得到的点云数据为list类型,首先进行数据类型的转换,然后体素滤波,对数据进行下采样,减少数据量
p = pcl.PointCloud(np.array(data, dtype=np.float32)) # 类型的转换
filter_vox = p.make_voxel_grid_filter() # 体素滤波器
filter_vox.set_leaf_size(0.005, 0.005, 0.005) # 体素的大小,米
cloud_filtered = filter_vox.filter() # 滤波,得到的数据类型为点云
2.平面分割,为github上的例子
seg = cloud_filtered.make_segmenter_normals(ksearch=50) # 平面分割
seg.set_optimize_coefficients(True)
seg.set_model_type(pcl.SACMODEL_NORMAL_PLANE)
seg.set_method_type(pcl.SAC_RANSAC)
seg.set_distance_threshold(0.01)
seg.set_normal_distance_weight(0.01)
seg.set_max_iterations(100)
indices, coefficients = seg.segment()
具体的参数设置没有研究,但是相对于下面这个代码,上面的这个分割程序结果更好些
seg = cloud_filtered.make_segmenter()
seg.set_optimize_coefficients(True)
seg.set_model_type(pcl.SACMODEL_PLANE)
seg.set_method_type(pcl.SAC_RANSAC)
seg.set_distance_threshold(0.005)
indices, coefficients = seg.segment()
coefficients 是得到的平面ax + by +cz +d = 0的参数
coefficients[0],coefficients[1],coefficients[2],coefficients[3]
indices是得到的平面点云的索引
for i in range(len(indices)):
print(str(indices[i]) + ', x: ' + str(cloud_filtered[indices[i]][0]) + ', y : ' +str(cloud_filtered[indices[i]][1]) + ', z : ' + str(cloud_filtered[indices[i]][2]))
3.将分割得到的平面的点去除
q = cloud_filtered.extract(indices, True)
4.去除平面点后还有一些离群点,用离群点滤波器进行再次滤波
filter_stat = cloud_filtered_outdices.make_statistical_outlier_filter()
filter_stat.set_mean_k(50)
filter_stat.set_std_dev_mul_thresh(1.0)
p = filter_stat.filter()
上一篇: pcl教程(三)点云平面分割
下一篇: 3.3