pcl笔记

1直线拟合

import pcl

def fit_line_model(pcd):
    """Fits a line by RANSAC method to points in pcd."""
    ransac_distance_threshold = 0.03
    if pcd.size == 0:
        return None
    point_cloud = pcl.PointCloud(pcd.astype(np.float32))
    seg = point_cloud.make_segmenter_normals(ksearch=50)

    seg.set_model_type(pcl.SACMODEL_LINE)
    seg.set_method_type(pcl.SAC_RANSAC)
    seg.set_max_iterations(1000)
    seg.set_distance_threshold(ransac_distance_threshold)
    indices, model = seg.segment()
    inlier_ratio = np.float(len(indices)) / arr.shape[0]
    logging.info("percentage of points in line model: %f", inlier_ratio)

    if inlier_ratio < 0.5:
        logging.warn('Refuse this line model because of less than half of its.'
                     'points are selected by ransac method.')
        return None

    return model

2 python pcl tutorial : https://python-pcl-fork.readthedocs.io/en/latest/tutorial/

你可能感兴趣的:(pcl,直线拟合)