def Vis_Skeleton_2D_coco()

in renderer/viewer2D.py [0:0]


def Vis_Skeleton_2D_coco(pt2d, pt2d_visibility = None, image = None,  bVis = False, color=None , offsetXY =None):
    pt2d = np.reshape(pt2d,(-1,2))          #Just in case. Make sure (32, 2)

    #Draw via opencv
    if not isinstance(image, np.ndarray):#not image: #If no image is given, generate Blank image
        image = np.ones((1000,1000,3),np.uint8) *255

    radius = 4

    # 'OP RHip', 'OP RKnee', 'OP RAnkle',             #9,10,11
    # 'OP LHip', 'OP LKnee', 'OP LAnkle',             #12,13,14
    # 'OP REye', 'OP LEye', 'OP REar',                #15,16,17
    # 'OP LEar', 'OP LBigToe', 'OP LSmallToe',        #18,19,20
    # 'OP LHeel', 'OP RBigToe', 'OP RSmallToe', 'OP RHeel',  #21, 22, 23, 24  ##Total 25 joints  for openpose
    link_coco = [  [0,1], [1,3] , [0,2] , [2,4],
                [6,8],[8,10],      #Right Arm
                [5,7], [7,9],       #Left Arm
                [15,13], [13,11], [11,5],    #Left Leg
                [16,14], [14,12], [12,6], #Right left
                ]

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

    # # #Openpose joint drawn as blue
    for k in np.arange( len(link_coco) ):
        parent = link_coco[k][0]
        child = link_coco[k][1]
        if color is not None:
            c = color
        else:
            if True:#bLeft[k]:
                c = (255,0,0)#BGR, Blue
            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 bVis:
        ImShow(image)
    return image