Pyplot中Scatter三维散点图制作方法记录

Pyplot中Scatter三维散点图制作方法记录

简介

物体识别是深度相机的应用方向之一,根据本工作已经做了平面、球体、圆柱体的识别算法,在这些算法中,点云必须属于单一物体,不能同时存在多个物体。这个要求并不符合实际应用,因为在实际中,被深度相机观测的物体往往是放置于台面、地面、支架上,或者同时存在多个物体,比如放在桌上的一筐苹果,这就产生了多物体识别的问题。

本工作中,多物体识别在算法层面采用RANSAC方法,程序层面采用CGAL库。感谢CGAL的支持,可以对包括平面、球、圆柱、圆锥、甜甜圈等几何体进行识别,并且能够实现多物体的识别。

三维散点图可以直观地展示多物体识别的效果,本工作使用Python的scatter函数实现。

三维散点图制作

    # figure
    fig = plt.figure(dpi=128,figsize=(8,8))
    ax = fig.add_subplot(111, projection='3d')

    for i, name in enumerate(ShapeList):
        print('shapeName:',name)

        XCur = []
        YCur = []
        ZCur = []
        for j, nameCur in enumerate(ShapeName):
            if name==nameCur:
                XCur.append(X[j])
                YCur.append(Y[j])
                ZCur.append(Z[j])

        XCur = np.array(XCur)
        YCur = np.array(YCur)
        ZCur = np.array(ZCur)

        # Random sampling
        #size = int(len(XCur)/2)
        #index = np.random.choice(XCur.shape[0], size, replace=False)
        #XCur = XCur[index]
        #YCur = YCur[index]
        #ZCur = ZCur[index]

        # draw
        ax.scatter(XCur, YCur, ZCur, s=5, cmap="jet", marker="o", label=name)

    # set lable 
    ax.set_xlabel('X', fontsize=10)
    ax.set_ylabel('Y', fontsize=10)
    ax.set_zlabel('Z', fontsize=10)

    # set limits
    #ax.set_xlim(-200, 200)
    #ax.set_ylim(-200,200)
    #ax.set_zlim(-150, 50)
       
    # draw
    ax.scatter(XCur, YCur, ZCur, s=5, cmap="jet", marker="o", label=name)

    # set lable 
    ax.set_xlabel('X', fontsize=10)
    ax.set_ylabel('Y', fontsize=10)
    ax.set_zlabel('Z', fontsize=10)

    # set limits
    #ax.set_xlim(-200, 200)
    #ax.set_ylim(-200,200)
    #ax.set_zlim(-150, 50)

    # set title
    plt.title('Shape Detection', fontsize=10)

    # overlapping 
    plt.tight_layout()

    # legend
    plt.legend()

    # save figure
    plt.savefig('figure_step5_shapeDetection.png')

    # print figure on screen
    plt.show()

效果如图

《Pyplot中Scatter三维散点图制作方法记录》

    原文作者:PascalXie
    原文地址: https://blog.csdn.net/qq_32454557/article/details/112316237
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞