Example #1
0
def estimate_paf(peaks, heat_mat, paf_mat):

    pafprocess.process_paf(peaks, heat_mat, paf_mat)
    print('human num is',pafprocess.get_num_humans())
    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
Example #2
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

            #print(f"human_id : {human_id}")

            for part_idx in range(18):
                # JS print
                #print(f"part_idx : {part_idx}")

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

                #print(f"c_idx : {c_idx}")

                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))
                #print(f"human.body_parts[{part_idx}] : {human.body_parts[part_idx]}\n")

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

        return humans
Example #3
0
    def estimate_paf(peaks, heat_mat, paf_mat):
        pafprocess.process_paf(peaks, heat_mat, paf_mat)

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

            for part_idx in range(18):
                c_idx = int(pafprocess.get_part_cid(human_id, part_idx))
                if c_idx < 0:
                    #MODIFIED CODE TO MAKE IT BEAUTIFULLY WORK ZANZONELLI
                    human.x_parts.append(0)
                    humanArray.append(0)
                    human.y_parts.append(0)
                    humanArray.append(0)
                    human.scores.append(0)
                    humans.append(human)
                    continue

                is_added = True

                #RICCARDO //TODO
                human.x_parts.append(float(pafprocess.get_part_x(c_idx)))
                human.y_parts.append(float(pafprocess.get_part_y(c_idx)))
                human.scores.append(pafprocess.get_part_score(c_idx))

                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))
                humanArray.append(float(pafprocess.get_part_x(c_idx)) * 2)
                humanArray.append(float(pafprocess.get_part_y(c_idx)) * 2)

            if is_added:
                score = pafprocess.get_score(human_id)
                human.score = score
                humans.append(human)
                humansArray.append(humanArray)
                #print ("HUMANS LEN",len(humans)," ARRHUMANS LEN",len(humansArray),humanArray)

        return humans, humansArray
    def estimate_paf(peaks,
                     heat_mat,
                     paf_mat,
                     offset=(0, 0),
                     shape=(0, 0),
                     full_shape=(0, 0)):
        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
                if shape[0] != 0:
                    x = (float(pafprocess.get_part_x(c_idx)) /
                         heat_mat.shape[1] * shape[0] +
                         offset[0]) / full_shape[0]
                    y = (float(pafprocess.get_part_y(c_idx)) /
                         heat_mat.shape[0] * shape[1] +
                         offset[1]) / full_shape[1]
                else:
                    x = float(pafprocess.get_part_x(c_idx)) / heat_mat.shape[1]
                    y = float(pafprocess.get_part_y(c_idx)) / heat_mat.shape[0]
                human.body_parts[part_idx] = BodyPart(
                    '%d-%d' % (human_id, part_idx), part_idx, x, y,
                    pafprocess.get_part_score(c_idx))

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

        return humans
Example #5
0
    def estimate_paf(peaks, heat_mat, paf_mat):
        pafprocess.process_paf(peaks, heat_mat, paf_mat)

        humans = []
        #pafprocess.get_num_humans()
        num_hum = pafprocess.get_num_humans()
        if num_hum > 0:
            for human_id in range(1):
                human = Human([])
                is_added = False

                try:
                    c_idx = int(pafprocess.get_part_cid(human_id, 1))
                    difference_x = 0.50 - float(
                        pafprocess.get_part_x(c_idx)) / heat_mat.shape[1]
                    difference_y = 0.50 - float(
                        pafprocess.get_part_y(c_idx)) / heat_mat.shape[0]
                    c_idx = int(pafprocess.get_part_cid(human_id, 5))
                    shoulder_1 = float(
                        pafprocess.get_part_x(c_idx)) / heat_mat.shape[1]
                    c_idx = int(pafprocess.get_part_cid(human_id, 2))
                    shoulder_2 = float(
                        pafprocess.get_part_x(c_idx)) / heat_mat.shape[1]
                    prop_coeff = 0.10 / (shoulder_1 - shoulder_2)
                except:
                    prop_coeff = 1
                    difference_x = 0
                    difference_y = 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

                    x_idx_part = ((float(pafprocess.get_part_x(c_idx)) /
                                   heat_mat.shape[1]) + difference_x -
                                  0.50) * prop_coeff + 0.50
                    y_idx_part = ((float(pafprocess.get_part_y(c_idx)) /
                                   heat_mat.shape[0]) + difference_y -
                                  0.50) * prop_coeff + 0.50

                    print(
                        "====================================================="
                    )
                    print(f"Your {part_idx} is at {x_idx_part} X")
                    print(f"Your {part_idx} is at {y_idx_part} Y")
                    print(
                        "====================================================="
                    )

                    human.body_parts[part_idx] = BodyPart(
                        '%d-%d' % (human_id, part_idx), part_idx, x_idx_part,
                        y_idx_part, pafprocess.get_part_score(c_idx))

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


# =============================================================================
#                 print("=====================================================")
#                 print(human.body_parts[0].values[1])
#                 print("====================================================")
# =============================================================================
                humans.append(human)

        return humans
Example #6
0
    def estimate_paf(peaks, heat_mat, paf_mat, image_h, image_w, boxes=None, classes=None, scores=None):
        pafprocess.process_paf(peaks, heat_mat, paf_mat)

        humans = []
        humans_remove = []
        for human_id in range(pafprocess.get_num_humans()):
            subset_19 = int(pafprocess.get_part_cid(human_id, 19))
            subset_18 = int(pafprocess.get_part_cid(human_id, 18))

            if (subset_19 < 4 or (subset_18/subset_19 < 0.4)):
                continue
            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)

        print(boxes, classes,  scores)
        if classes is not None:
            person_arg = np.argwhere(classes == 0)
            boxes_person = boxes[person_arg]
            scores_person = scores[person_arg]
            print("Human data", boxes_person, scores_person)

            animal_arg = np.argwhere(np.logical_and(np.greater_equal(classes,15), np.less_equal(classes,23)))
            #teddy_arg = np.where(classes==77)
            #animal_arg = np.concatenate((animal_arg, teddy_arg), axis = 0)
            boxes_animals = boxes[animal_arg]
            scores_animals = scores[animal_arg]
            print("Animal data", boxes_animals, scores_animals)

        print(humans)

        if boxes_animals is not None or boxes_animals:
            for box in boxes_animals:
                x, y, w, h = box[:,0], box[:,1], box[:,2], box[:,3]
                for human in humans:
                    part = 0
                    part_check = 0
                    for i in range(common.CocoPart.Background.value):
                        if i not in human.body_parts.keys():
                            continue
                        part = part + 1

                        body_part = human.body_parts[i] 
                        center = (int(body_part.x * image_w + 0.5), int(body_part.y * image_h + 0.5))
                        print(center)
                        if (center[0]>x and center[0]<(x+w) and center[1]>y and center[1]<(y+h)):
                            part_check = part_check + 1

                    if (part == part_check):
                        #remove this human
                        print("An incorrect human pose found")
                        humans_remove.append(human)
            for x in humans_remove:
                humans.remove(x)

        print(humans)

        # below in my code        
        if boxes_person is not None or boxes_person:
            for box in boxes_person:
                x, y, w, h = box[:,0], box[:,1], box[:,2], box[:,3]
                print(x,y,w,h)
                flag = 0
                for human in humans:
                    part = 0
                    for i in range(common.CocoPart.Background.value):
                        if i not in human.body_parts.keys():
                            continue

                        body_part = human.body_parts[i] 
                        center = (int(body_part.x * image_w + 0.5), int(body_part.y * image_h + 0.5))
                        print(center)
                        if not(center[0]>x and center[0]<(x+w) and center[1]>y and center[1]<(y+h)):
                            
                            part = part+1
                            if (part == 3):
                                part = 0
                                flag = flag + 1
                                break
                    
                if (flag == len(humans)):
                    print(flag)
                    print("open pose not detected for person")
                    print(pafprocess.get_num_humans())
                    for human_id in range(pafprocess.get_num_humans()):
                        human = Human([])
                        part = 0

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

                            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)
                            )
                            body_part = human.body_parts[part_idx] 
                            center = (int(body_part.x * image_w + 0.5), int(body_part.y * image_h + 0.5))
                            if not(center[0]>x and center[0]<(x+w) and center[1]>y and center[1]<(y+h)):
                                part = part+1
                                if (part == 3):
                                    print("This pose is not the one for the given bounding box")
                                    break

                        if (part<3):
                            score = pafprocess.get_score(human_id)
                            print("detected_suspect: ",part)
                            human.score = score
                            humans.append(human)
                            break

        print(humans)

        return humans