コード例 #1
0
ファイル: mpi_parse.py プロジェクト: dragonfly90/mx-openpose
def generateLabelMap(oneimg):

    ori_img = cv2.imread(oneimg['img_path'])
    ori_img_shape = ori_img.shape
    fscale = 368.0 / max(ori_img_shape[0], ori_img_shape[1])
    img_pad = padimg(ori_img, 368)
    thre = 0.5
    crop_size_width = 368
    crop_size_height = 368

    augmentcols = 368
    augmentrows = 368
    stride = 8
    grid_x = augmentcols / stride
    grid_y = augmentrows / stride
    sigma = 7.0

    heat_map = list()
    for i in range(numofparts + 1):
        heat_map.append(
            np.zeros((crop_size_width / stride, crop_size_height / stride)))

    for one_rect in oneimg['annoations']:
        for onePoint in one_rect['annopoints']:
            x, y, part_id, isVisible = onePoint
            x *= fscale
            y *= fscale
            x = int(x)
            y = int(y)
            part_id = part2ours[part_id] - 1
            if part_id <= -1:
                continue
            cv2.circle(heat_map[part_id], (x, y), 8, (1, 1, 1), -1, 8)

            putGaussianMaps(heat_map[part_id], 368, 368, x, y, stride, grid_x,
                            grid_y, sigma)

    ### put background channel
    #heat_map[numofparts] = heat_map[0]
    heat_map[numofparts] = np.max(heat_map[:-1], axis=0)
    # for g_y in range(heat_map[0].shape[0]):
    #     for g_x in range(heat_map[0].shape[1]):
    #         maximum=0
    #         for i in range(numofparts):
    #             if maximum<heat_map[i][g_y, g_x]:
    #                 maximum = heat_map[i][g_y, g_x]
    #         heat_map[numofparts][g_y,g_x]=max(maximum,0.0)

    mid_1 = [13, 14, 14, 1, 2, 4, 5, 1, 7, 8, 4, 10, 11]
    mid_2 = [14, 1, 4, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12]
    thre = 1

    pag_map = list()
    for i in range(numoflinks * 2):
        pag_map.append(np.zeros((46, 46)))

    count = np.zeros((46, 46))

    for one_rect in oneimg['annoations']:
        one_person = map2Ai(one_rect, fscale)
        for i in range(numoflinks):
            putVecMaps(pag_map[2 * i], pag_map[2 * i + 1], count,
                       one_person[mid_1[i] - 1][0],
                       one_person[mid_1[i] - 1][1],
                       one_person[mid_2[i] - 1][0],
                       one_person[mid_2[i] - 1][1], stride, 46, 46, sigma,
                       thre)
    # for i in range(len(heat_map)):
    #     heat_map[i]= cv2.resize(heat_map[i],(46,46),interpolation=cv2.INTER_NEAREST)
    return img_pad, heat_map, pag_map, genMask(oneimg,
                                               fscale).astype(np.float32)
コード例 #2
0
def generateLabelMap(img_aug, meta):
    thre = 1
    crop_size_width = 368
    crop_size_height = 368

    augmentcols = 368
    augmentrows = 368
    stride = 8
    grid_x = augmentcols / stride
    grid_y = augmentrows / stride
    sigma = 7.0

    heat_map = list()
    for i in range(19):
        heat_map.append(
            np.zeros((crop_size_width / stride, crop_size_height / stride)))

    for i in range(18):
        if (meta['joint_self']['isVisible'][i] <= 1):
            putGaussianMaps(heat_map[i], 368, 368,
                            meta['joint_self']['joints'][i]['x'],
                            meta['joint_self']['joints'][i]['y'], stride,
                            grid_x, grid_y, sigma)

        for j in meta['joint_others']:
            if (meta['joint_others'][j]['isVisible'][i] <= 1):
                putGaussianMaps(heat_map[i], 368, 368,
                                meta['joint_others'][j]['joints'][i]['x'],
                                meta['joint_others'][j]['joints'][i]['y'],
                                stride, grid_x, grid_y, sigma)

    ### put background channel

    for g_y in range(grid_y):
        for g_x in range(grid_x):
            maximum = 0
            for i in range(18):
                if maximum < heat_map[i][g_y, g_x]:
                    maximum = heat_map[i][g_y, g_x]
            heat_map[18][g_y, g_x] = max(1.0 - maximum, 0.0)

    mid_1 = [2, 9, 10, 2, 12, 13, 2, 3, 4, 3, 2, 6, 7, 6, 2, 1, 1, 15, 16]
    mid_2 = [
        9, 10, 11, 12, 13, 14, 3, 4, 5, 17, 6, 7, 8, 18, 1, 15, 16, 17, 18
    ]

    #mid_1 = [2, 2, 3, 4, 6, 7, 2, 9, 10, 2, 12, 13, 2, 1, 15, 1, 16, 3, 6]
    #mid_2 = [3, 6, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 1, 15, 17, 16, 18, 17, 18]

    thre = 1

    pag_map = list()
    for i in range(38):
        pag_map.append(np.zeros((46, 46)))

    for i in range(19):
        count = np.zeros((46, 46))
        jo = meta['joint_self']

        if (jo['isVisible'][mid_1[i] - 1] <= 1
                and jo['isVisible'][mid_2[i] - 1] <= 1):
            putVecMaps(pag_map[2 * i], pag_map[2 * i + 1], count,
                       jo['joints'][mid_1[i] - 1]['x'],
                       jo['joints'][mid_1[i] - 1]['y'],
                       jo['joints'][mid_2[i] - 1]['x'],
                       jo['joints'][mid_2[i] - 1]['y'], stride, 46, 46, sigma,
                       thre)

        for j in meta['joint_others']:
            jo = meta['joint_others'][j]
            if (jo['isVisible'][mid_1[i] - 1] <= 1
                    and jo['isVisible'][mid_2[i] - 1] <= 1):
                putVecMaps(pag_map[2 * i], pag_map[2 * i + 1], count,
                           jo['joints'][mid_1[i] - 1]['x'],
                           jo['joints'][mid_1[i] - 1]['y'],
                           jo['joints'][mid_2[i] - 1]['x'],
                           jo['joints'][mid_2[i] - 1]['y'], stride, 46, 46,
                           sigma, thre)

    return (heat_map, pag_map)