コード例 #1
0
    def estimate_paf(peaks, heat_mat, paf_mat):
        pafprocess.process_paf(peaks, heat_mat, paf_mat)

        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)) / heat_mat.shape[1],
                    float(pafprocess.get_part_y(c_idx)) / heat_mat.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
        #Particule Affinity Field to separate people
        pafprocess.process_paf(peaks.astype('float32'),
                               heatMat.astype('float32'),
                               pafMat.astype('float32'))

        humans = []
        for human_id in range(pafprocess.get_num_humans()):
            body_parts = [(0.0, 0.0)] * 18
            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
                body_parts[part_idx] = (pafprocess.get_part_x(c_idx),
                                        pafprocess.get_part_y(c_idx))
            body_parts = np.array(
                [[body_parts[i][0] * scale, body_parts[i][1] * scale]
                 for i in range(18)]).flatten()
            humans.append(body_parts)

        # Draw human body parts
        d = ImageDraw.Draw(resized)
        for _data in humans:
            for pair in connections:
                if (_data[pair[0] * 2], _data[pair[0] * 2 + 1]) != (0, 0) and (
                        _data[pair[1] * 2], _data[pair[1] * 2 + 1]) != (0, 0):
                    d.line([(_data[pair[0] * 2], _data[pair[0] * 2 + 1]),
                            (_data[pair[1] * 2], _data[pair[1] * 2 + 1])],
                           fill=(255, 255, 255),
                           width=2)