Пример #1
0
def show_3d_skeleton(joints, limbs, params = None):
    """
    joints is n x 3 matrix
    """
    from matplotlib import pyplot as plt
    import imgproc
    ax = plt.gca()
    if not params:
        params = {}
    if 'elev' in params and 'azim' in params:
        # ax.view_init(elev=-89, azim=-107.) # for camera one
        ax.view_init(elev=params['elev'], azim=params['azim'])
    n_lim = len(limbs)
    joints = joints.reshape((-1, 3), order='C')
    if 'order' in params:
        tdic = {'x':0,'y':1,'z':2}
        assert(params['order'] in tdic)
        order_idx = tdic[params['order']]
        limb_order = sorted(range(n_lim), key=lambda k:(joints[limbs[k][0]][order_idx] + joints[limbs[k][1]][order_idx]),reverse=True)
    else:
        limb_order = range(n_lim)

    c = params['color'] if 'color' in params else imgproc.get_color_list(n_lim)
    lw = params['linewidth'] if 'linewidth' in params else 8
    for k in limb_order:
        l = limbs[k]
        j1 = joints[l[0]]
        j2 = joints[l[1]]
        x,y,z = [j1[0], j2[0]], [j1[1], j2[1]], [j1[2], j2[2]]
        ax.plot(x, y, z, c = c[k],linewidth=lw)
        
        # show doesn't work
        # use save
        plt.savefig('re.png')
Пример #2
0
def show_2d_skeleton(joints, limbs, params = None):
    """
    joints is n x 2 matrix
    
    """
    import imgproc
    ax = plt.gca()
    if not params:
        params = {}
    joints = joints.reshape((-1, 2), order='C')
    n_lim = len(limbs)
    c = params['color'] if 'color' in params else imgproc.get_color_list(n_lim)
    for i,l in enumerate(limbs):
        j1 = joints[l[0]]
        j2 = joints[l[1]]
        x,y = [j1[0], j2[0]], [j1[1], j2[1]]
        ax.plot(x, y, c = c[i])