def Vis_Skeleton_2D_smplCOCO()

in renderer/viewer2D.py [0:0]


def Vis_Skeleton_2D_smplCOCO(pt2d, pt2d_visibility=None, image = None, blankImSize = 1000, bVis = False, color=None, bBoxWidth=None):
    pt2d = np.reshape(pt2d,[-1,2])          #Just in case. Make sure (32, 2)


    if pt2d_visibility is not None and len(pt2d_visibility) == len(pt2d)*2:
        pt2d_visibility = pt2d_visibility[::2]
    #Draw via opencv
    if not isinstance(image, np.ndarray):#not image: #If no image is given, generate Blank image
        image = np.ones((blankImSize,blankImSize,3),np.uint8) *255

    radius = 4

    if(pt2d.shape[0]==19 or pt2d.shape[0]==20):
        # print("Vis_Skeleton_2D_smplCOCO: {} joints".format(16))
        #Without Nose
        link2D = [ [12,2], [2,1], [1,0], #Right leg
                     [12,3], [3,4], [4,5], #Left leg
                     [12,9], [9,10], [10,11], #Left Arm
                     [12,8], [8,7], [7,6], #Right shoulder
                      [12,14],[14,16],[16,18],  #Neck(12)->Nose(14)->rightEye(16)->rightEar(18)
                      [14,15],[15,17],   #Nose(14)->leftEye(15)->leftEar(17).
                      [14,13] #Nose->headTop(13)
                     ]
        bLeft = [ 0,0,0,
            1, 1, 1,
            0,0,0,
            1,1,1,
            1,1,1,
            11,0,11,0]
    elif(pt2d.shape[0]==18): #No head (13)
        # print("Vis_Skeleton_2D_smplCOCO: {} joints".format(16))
        #Without Nose
        link2D = [ [12,2], [2,1], [1,0], #Right leg
                     [12,3], [3,4], [4,5], #Left leg
                     [12,9], [9,10], [10,11], #Left Arm
                     [12,8], [8,7], [7,6], #Right shoulder
                      [12,13],[13,15],[15,17],  #Neck(12)->Nose(14)->rightEye(16)->rightEar(18)
                      [13,14],[14,16]   #Nose(14)->leftEye(15)->leftEar(17).
                    #   [14,13] #Nose->headTop(13)
                     ]
        bLeft = [ 0,0,0,
            1, 1, 1,
            1,1,1,
            0,0,0,
            1,0,0,
            1,1]
    elif(pt2d.shape[0]==26): #SMPLCOCO totalCpa26
        #Without Nose
        link2D = [ [12,2], [2,1], [1,0], #Right leg
                    [12,3], [3,4], [4,5], #Left leg
                    [12,9], [9,10], [10,11], #Left Arm
                    [12,8], [8,7], [7,6], #Right shoulder
                    [12,14],[14,16],[16,18],  #Neck(12)->Nose(14)->rightEye(16)->rightEar(18)
                    [14,15],[15,17],   #Nose(14)->leftEye(15)->leftEar(17).
                    # [14,13], #Nose->headMidle(13)
                    [12,19],       #headTop19
                    [5,20], [5,21], [5,22],       #leftFoot
                    [0,23], [0,24], [0,25]       #rightFoot
                    ]
        bLeft = [ 0,0,0,
            1, 1, 1,
            1,1,1,
            0,0,0,
            1,0,0,
            1,1,
            1,
            1,1,1,
            0,0,0]

    else:
        assert False

    # for i in np.arange( len(link) ):
    for k in np.arange( len(pt2d) ):
        if pt2d_visibility is None:
            cv2.circle(image, (int(pt2d[k][0]), int(pt2d[k][1]) ), radius, (0,255,0),-1)
        else:
            if pt2d_visibility[k]:
                cv2.circle(image, (int(pt2d[k][0]), int(pt2d[k][1]) ), radius, (0,255,0),-1)

    for k in np.arange( len(link2D) ):
        parent = link2D[k][0]
        child = link2D[k][1]
        if color is not None:
            c = color
        else:
            if bLeft[k]:
                c = (0,0,255)#BGR, RED
            else:
                c = (0,0,0)
        if pt2d_visibility is None:
            cv2.line(image, (int(pt2d[parent][0]), int(pt2d[parent][1])), (int(pt2d[child][0]), int(pt2d[child][1])), c, radius - 2)
        else:
            if pt2d_visibility[parent] and pt2d_visibility[child]:
                cv2.line(image, (int(pt2d[parent][0]), int(pt2d[parent][1])), (int(pt2d[child][0]), int(pt2d[child][1])), c, radius - 2)


    if bBoxWidth is not None:
        image = Vis_Bbox_minmaxPt(image, [0,0], [bBoxWidth,bBoxWidth])

    if bVis:
        ImShow(image,name='Vis_Skeleton_2D_smplCOCO')
    return image