示例#1
0
def paf_to_pose_cpp(heatmaps, pafs, config):
    humans = []
    joint_list_per_joint_type = NMS(heatmaps,
                                    upsampFactor=config.MODEL.DOWNSAMPLE,
                                    config=config)

    joint_list = np.array([
        tuple(peak) + (joint_type, )
        for joint_type, joint_peaks in enumerate(joint_list_per_joint_type)
        for peak in joint_peaks
    ]).astype(np.float32)

    if joint_list.shape[0] > 0:
        joint_list = np.expand_dims(joint_list, 0)
        paf_upsamp = cv2.resize(pafs,
                                None,
                                fx=config.MODEL.DOWNSAMPLE,
                                fy=config.MODEL.DOWNSAMPLE,
                                interpolation=cv2.INTER_NEAREST)
        heatmap_upsamp = cv2.resize(heatmaps,
                                    None,
                                    fx=config.MODEL.DOWNSAMPLE,
                                    fy=config.MODEL.DOWNSAMPLE,
                                    interpolation=cv2.INTER_NEAREST)
        pafprocess.process_paf(joint_list, heatmap_upsamp, paf_upsamp)
        for human_id in range(pafprocess.get_num_humans()):
            human = Human([])
            is_added = False
            for part_idx in range(config.MODEL.NUM_KEYPOINTS):
                c_idx = int(pafprocess.get_part_cid(human_id, part_idx))
                if c_idx < 0:
                    continue
                is_added = True
                human.body_parts[part_idx] = BodyPart(
                    '%d-%d' % (human_id, part_idx), part_idx,
                    float(pafprocess.get_part_x(c_idx)) /
                    heatmap_upsamp.shape[1],
                    float(pafprocess.get_part_y(c_idx)) /
                    heatmap_upsamp.shape[0], pafprocess.get_part_score(c_idx))
            if is_added:
                score = pafprocess.get_score(human_id)
                human.score = score
                humans.append(human)

    return humans
示例#2
0
    for i in range(19):
        heatmap_peaks[:,:,i] = find_peaks(heatmap[:,:,i])
    heatmap_peaks = heatmap_peaks.astype(np.float32)
    heatmap = heatmap.astype(np.float32)
    paf = paf.astype(np.float32)

    #C++ postprocessing      
    pafprocess.process_paf(heatmap_peaks, heatmap, paf)

    humans = []
    for human_id in range(pafprocess.get_num_humans()):
        human = Human([])
        is_added = False

        for part_idx in range(18):
            c_idx = int(pafprocess.get_part_cid(human_id, part_idx))
            if c_idx < 0:
                continue

            is_added = True
            human.body_parts[part_idx] = BodyPart(
                '%d-%d' % (human_id, part_idx), part_idx,
                float(pafprocess.get_part_x(c_idx)) / heatmap.shape[1],
                float(pafprocess.get_part_y(c_idx)) / heatmap.shape[0],
                pafprocess.get_part_score(c_idx)
            )

        if is_added:
            score = pafprocess.get_score(human_id)
            human.score = score
            humans.append(human)