Exemple #1
0
 def rotate_existing_landmarks(self, frame, dimensions):
     """ Backwards compatability fix. Rotates the landmarks to
         their correct position and deletes r """
     for face in self.get_alignments_for_frame(frame):
         angle = face.get("r", 0)
         if not angle:
             return
         rotation_matrix = self.get_original_rotation_matrix(
             dimensions, angle)
         rotate_landmarks(face, rotation_matrix)
         del face["r"]
Exemple #2
0
 def rotate_existing_landmarks(self, frame, dimensions):
     """ Backwards compatability fix. Rotates the landmarks to
         their correct position and sets r to 0 """
     for alignment in self.alignments.get(frame, list()):
         angle = alignment.get("r", 0)
         if not angle:
             return
         rotation_matrix = self.get_original_rotation_matrix(
             dimensions, angle)
         rotate_landmarks(alignment, rotation_matrix)
         del alignment["r"]
    def rotate_existing_landmarks(self, frame_name):
        """ Backwards compatability fix. Rotates the landmarks to
            their correct position and deletes r

            NB: The original frame dimensions must be passed in otherwise
            the transformation cannot be performed """
        for face in self.get_faces_in_frame(frame_name):
            angle = face.get("r", 0)
            if not angle:
                return
            dims = face["frame_dims"]
            r_mat = self.get_original_rotation_matrix(dims, angle)
            rotate_landmarks(face, r_mat)
            del face["r"]
Exemple #4
0
    def rotate_existing_landmarks(self, frame_name, frame):
        """ Backwards compatability fix. Rotates the landmarks to
            their correct position and deletes r

            NB: The original frame must be passed in otherwise
            the transformation cannot be performed """
        logger.trace("Rotating existing landmarks for frame: '%s'", frame_name)
        dims = frame.shape[:2]
        for face in self.get_faces_in_frame(frame_name):
            angle = face.get("r", 0)
            if not angle:
                logger.trace("Landmarks do not require rotation: '%s'", frame_name)
                return
            logger.trace("Rotating landmarks: (frame: '%s', angle: %s)", frame_name, angle)
            r_mat = self.get_original_rotation_matrix(dims, angle)
            rotate_landmarks(face, r_mat)
            del face["r"]
        logger.trace("Rotatated existing landmarks for frame: '%s'", frame_name)
Exemple #5
0
 def rotate_existing_landmarks(self, frame, dimensions):
     """ Backwards compatability fix. Rotates the landmarks to
         their correct position and sets r to 0 """
     for alignment in self.alignments.get(frame, list()):
         angle = alignment.get("r", 0)
         if not angle:
             return
         rotation_matrix = self.get_original_rotation_matrix(dimensions,
                                                             angle)
         face = DetectedFace()
         face.alignment_to_face(None, alignment)
         face = rotate_landmarks(face, rotation_matrix)
         alignment = face.face_to_alignment(alignment)
         del alignment["r"]
Exemple #6
0
    def process_single_image(self, filename):
        """ Detect faces in an image. Rotate the image the specified amount
            until at least one face is found, or until image rotations are
            depleted.
            Once at least one face has been detected, pass to
            process_single_face to process the individual faces """
        retval = filename, list()
        try:
            image = Utils.cv2_read_write('read', filename)

            for angle in self.images.rotation_angles:
                currentimage, rotation_matrix = rotate_image_by_angle(
                    image, angle)
                faces = self.faces.get_faces(currentimage, angle)
                process_faces = [[idx, face] for idx, face in faces]
                if not process_faces:
                    continue

                if angle != 0 and self.args.verbose:
                    print("found face(s) by rotating image "
                          "{} degrees".format(angle))
                if angle != 0:
                    process_faces = [[
                        idx, rotate_landmarks(face, rotation_matrix)
                    ] for idx, face in process_faces]

                if process_faces:
                    break

            final_faces = [
                self.process_single_face(idx, face, filename, image)
                for idx, face in process_faces
            ]

            retval = filename, final_faces
        except Exception as err:
            if self.args.verbose:
                print("Failed to extract from image: "
                      "{}. Reason: {}".format(filename, err))
            raise
        return retval
Exemple #7
0
 def rotate_rect(bounding_box, rotation_matrix):
     """ Rotate a bounding box dict based on the rotation_matrix"""
     logger.trace("Rotating bounding box")
     bounding_box = rotate_landmarks(bounding_box, rotation_matrix)
     return bounding_box
Exemple #8
0
 def rotate_rect(d_rect, rotation_matrix):
     """ Rotate a dlib rect based on the rotation_matrix"""
     d_rect = rotate_landmarks(d_rect, rotation_matrix)
     return d_rect
Exemple #9
0
 def rotate_rect(bounding_box, rotation_matrix):
     """ Rotate a BoundingBox based on the rotation_matrix"""
     logger.trace("Rotating BoundingBox")
     bounding_box = rotate_landmarks(bounding_box, rotation_matrix)
     return bounding_box
Exemple #10
0
 def rotate_rect(d_rect, rotation_matrix):
     """ Rotate a dlib rect based on the rotation_matrix"""
     logger.trace("Rotating d_rectangle")
     d_rect = rotate_landmarks(d_rect, rotation_matrix)
     return d_rect