Exemple #1
0
    def _alignments_faces(self, frame_name, image):
        """ Return detected faces from an alignments file.

        Parameters
        ----------
        frame_name: str
            The name of the frame to return the detected faces for
        image: :class:`numpy.ndarray`
            The frame that the detected faces exist in

        Returns
        -------
        list
            List of :class:`lib.faces_detect.DetectedFace` objects
        """
        if not self._check_alignments(frame_name):
            return list()

        faces = self._alignments.get_faces_in_frame(frame_name)
        detected_faces = list()

        for rawface in faces:
            face = DetectedFace()
            face.from_alignment(rawface, image=image)
            detected_faces.append(face)
        return detected_faces
Exemple #2
0
 def extract_one_face(self, alignment, image):
     """ Extract one face from image """
     logger.trace("Extracting one face: (frame: '%s', alignment: %s)",
                  self.current_frame, alignment)
     face = DetectedFace()
     face.from_alignment(alignment, image=image)
     face.load_aligned(image, size=self.size, align_eyes=self.align_eyes)
     return face
Exemple #3
0
 def extract_one_face(self, alignment, image):
     """ Extract one face from image """
     logger.trace("Extracting one face: (frame: '%s', alignment: %s)",
                  self.current_frame, alignment)
     face = DetectedFace()
     face.from_alignment(alignment, image=image)
     face.load_aligned(image, size=self.size, align_eyes=self.align_eyes)
     return face
Exemple #4
0
 def extract_one_face(self, alignment, image):
     """ Extract one face from image """
     face = DetectedFace()
     face.from_alignment(alignment, image=image)
     face.load_aligned(image,
                       size=self.size,
                       padding=self.padding,
                       align_eyes=self.align_eyes)
     return face
Exemple #5
0
 def transform_landmarks(self, alignments):
     """ For each face transform landmarks and return """
     landmarks = dict()
     for _, faces, _, _ in alignments.yield_faces():
         for face in faces:
             detected_face = DetectedFace()
             detected_face.from_alignment(face)
             detected_face.load_aligned(None, size=self.size, align_eyes=False)
             landmarks[detected_face.hash] = detected_face.aligned_landmarks
     return landmarks
Exemple #6
0
 def load(self):
     """ Load the faces from the alignments file, convert to
     :class:`~lib.faces_detect.DetectedFace`. objects and add to :attr:`_frame_faces`. """
     for key in sorted(self._alignments.data):
         this_frame_faces = []
         for item in self._alignments.data[key]["faces"]:
             face = DetectedFace()
             face.from_alignment(item, with_thumb=True)
             this_frame_faces.append(face)
         self._frame_faces.append(this_frame_faces)
Exemple #7
0
    def alignments_faces(self, frame, image):
        """ Get the face from alignments file """
        if not self.check_alignments(frame):
            return list()

        faces = self.alignments.get_faces_in_frame(frame)
        detected_faces = list()

        for rawface in faces:
            face = DetectedFace()
            face.from_alignment(rawface, image=image)
            detected_faces.append(face)
        return detected_faces
Exemple #8
0
    def alignments_faces(self, frame, image):
        """ Get the face from alignments file """
        if not self.check_alignments(frame):
            return list()

        faces = self.alignments.get_faces_in_frame(frame)
        detected_faces = list()

        for rawface in faces:
            face = DetectedFace()
            face.from_alignment(rawface, image=image)
            detected_faces.append(face)
        return detected_faces
Exemple #9
0
    def alignments_faces(self, filename, frame):
        """ Get the face from alignments file """
        if not self.check_alignments(frame):
            return None

        faces = self.alignments.get_alignments_for_frame(frame)
        image = self.images.load_one_image(filename)
        detected_faces = list()

        for rawface in faces:
            face = DetectedFace()
            face.from_alignment(rawface, image=image)
            detected_faces.append(face)
        return image, detected_faces
Exemple #10
0
    def _get_detected_face(alignment):
        """ Convert an alignment dict item to a detected_face object

        Parameters
        ----------
        alignment: dict
            The alignment dict for a face

        Returns
        -------
        :class:`lib.FacesDetect.detected_face`:
            The corresponding detected_face object for the alignment
        """
        detected_face = DetectedFace()
        detected_face.from_alignment(alignment)
        return detected_face
Exemple #11
0
 def load_frames(self):
     """ Load a sample of random frames """
     self.input_images = list()
     for selection in self.random_choice:
         filename = os.path.basename(self.filelist[selection])
         image = self.images.load_one_image(self.filelist[selection])
         # Get first face only
         face = self.alignments.get_faces_in_frame(filename)[0]
         detected_face = DetectedFace()
         detected_face.from_alignment(face, image=image)
         self.input_images.append({"filename": filename,
                                   "image": image,
                                   "detected_faces": [detected_face]})
     self.display.source = self.input_images
     self.display.update_source = True
     logger.debug("Selected frames: %s", [frame["filename"] for frame in self.input_images])
Exemple #12
0
 def extract_one_face(self, alignment, image):
     """ Extract one face from image """
     face = DetectedFace()
     face.from_alignment(alignment, image=image)
     return self.extractor.extract(image, face, self.size, self.align_eyes)