Ejemplo n.º 1
0
    def match(self, new_human_detections, new_pose_estimations,
              new_face_detections, new_facial_landmarks, new_facial_emotions):

        face_indices = self.match_faces_with_body(new_human_detections,
                                                  new_face_detections)

        distances = np.array([[Util.bbox_distance_iou(new_human_detections[i].bounding_box, self.humans[j].human_bounding_box_path[-1].bounding_box) \
                                                    for j in range(len(self.humans))]
                                                    for i in range(len(new_human_detections))])
        if distances.shape[0] == 0:
            row_ind, col_ind = [], []
        else:
            row_ind, col_ind = scipy.optimize.linear_sum_assignment(-distances)

        unmatched_tracking_indices = []
        for j in range(len(self.humans)):
            # unmatched tracking
            if j not in col_ind:
                unmatched_tracking_indices.append(j)

        matched_detection_indices, unmatched_detection_indices = [], []
        for i in range(len(new_human_detections)):
            # matched detection
            if i in row_ind:
                j = col_ind[np.where(row_ind == i)[0][0]]
                matched_detection_indices.append([i, j])

            # unmatched detection
            else:
                unmatched_detection_indices.append(i)

        humans = []

        for inds in matched_detection_indices:
            i, j = inds
            human = self.humans[j]
            human.human_bounding_box_path.append(new_human_detections[i])
            human.human_pose_path.append(new_pose_estimations[i])
            human.face_bounding_box_path.append(
                new_face_detections[face_indices[i]])
            human.facial_landmarks_path.append(
                new_facial_landmarks[face_indices[i]])
            human.facial_emotion_path.append(
                new_facial_emotions[face_indices[i]])
            humans.append(human)

        for ind in unmatched_detection_indices:
            bounding_box = new_human_detections[ind]
            pose = new_pose_estimations[ind]
            face_bounding_box = new_face_detections[face_indices[ind]]
            facial_landmarks = new_facial_landmarks[face_indices[ind]]
            facial_emotion = new_facial_emotions[face_indices[ind]]
            humans.append(
                Person(bounding_box, pose, face_bounding_box, facial_landmarks,
                       facial_emotion))

        self.humans = humans
Ejemplo n.º 2
0
    def match(self, new_face_bboxes, new_facial_landmarks):

        distances = np.array([[Util.bbox_distance_iou(new_face_bboxes[i].bounding_box, self.humans[j].face_bounding_box_path[-1].bounding_box) \
                                                    for j in range(len(self.humans))]
                                                    for i in range(len(new_face_bboxes))])

        if distances.shape[0] == 0:
            row_ind, col_ind = [], []
        else:
            row_ind, col_ind = linear_sum_assignment(- distances)

        unmatched_tracking_indices = []
        for j in range(len(self.humans)):
            # unmatched tracking
            if j not in col_ind:
                unmatched_tracking_indices.append(j)

        matched_detection_indices, unmatched_detection_indices = [], []
        for i in range(len(new_face_bboxes)):
            # matched detection
            if i in row_ind:
                j = col_ind[np.where(row_ind == i)[0][0]]
                matched_detection_indices.append([i, j])

            # unmatched detection
            else:
                unmatched_detection_indices.append(i)

        humans = []

        for inds in matched_detection_indices:
            i, j = inds
            human = self.humans[j]
            human.face_bounding_box_path.append(new_face_bboxes[i])
            human.facial_landmarks_path.append(new_facial_landmarks[i])
            humans.append(human)

        self.humans = humans