基于法线的群集点3d云

时间:2019-02-25 14:57:23

标签: python 3d point-cloud-library point-clouds

我试图根据两个平面的法线聚类一个3D点云,我计算出正确的法线,如下图所示

enter image description here

将它们聚类时出现问题,我得到了不正确的聚类,应该有两个聚类。

enter image description here

这是数据集和代码:

def main():

    #process first point cloud
    f3data = np.loadtxt(r'c:\ahmed\bxz.csv', delimiter=',',
                        dtype=[('astand', np.str_, 20), ('x1', np.float32), ('x2', np.float32), ('x3', np.float32),
                               ])


    ptcloud_1 = np.vstack((f3data['x1'], f3data['x2'], f3data['x3'])).transpose()



    pc_1 = pcl.PointCloud.PointXYZ(ptcloud_1)

    X, final_point_cloud1 = filter_point_transform(pc_1)

    pcl.io.savePLYFileASCII("original_first.ply", final_point_cloud1)

    print("Load a ply point cloud, print it, and render it")
    pcd = open3d.read_point_cloud("original_first.ply")
    print(pcd)
    print(np.asarray(pcd.points))

    downpcd = open3d.voxel_down_sample(pcd, voxel_size = 0.05)


    #open3d.draw_geometries([pcd])
    print("Recompute the normal of the downsampled point cloud")
    open3d.estimate_normals(downpcd, search_param=open3d.KDTreeSearchParamHybrid(
        radius=1, max_nn=5))
    #open3d.draw_geometries([downpcd])
    print("Print a normal vector of the 0th point")
    print(downpcd.normals[0])
    print("Print the normal vectors of the first 10 points")
    print(np.asarray(downpcd.normals)[:10,:])
    print("")
    open3d.draw_geometries([downpcd])

    from sklearn.cluster import KMeans
    kmeans = KMeans(algorithm='auto', n_clusters=2, init='k-means++', max_iter=12250, n_init=100, random_state=0)
    y_kmeans = kmeans.fit_predict(np.asarray(downpcd.normals))
    print(kmeans.labels_)
    import mpl_toolkits.mplot3d as m3d

    plt.figure('K-Means on Iris Dataset', figsize=(7, 7))
    ax = plt.axes(projection='3d')
    ax.scatter(X[28:, 1], X[28:, 0], X[28:, 2], c=kmeans.labels_, cmap='Set2', s=50)

    plt.show()

https://www.mediafire.com/file/midx8g7p72a37w2/bxz.csv/file

0 个答案:

没有答案