Ejemplo n.º 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
Ejemplo n.º 2
0
        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)
            
    out = draw_humans(oriImg, humans)

        # Display the resulting frame
        cv2.imshow('Video', out)

        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    # When everything is done, release the capture
    video_capture.release()
    cv2.destroyAllWindows()