def _output_processing(self, extract_media, size): """ Prepare faces for output Loads the aligned face, generate the thumbnail, perform any processing actions and verify the output. Parameters ---------- extract_media: :class:`plugins.extract.pipeline.ExtractMedia` Output from :class:`plugins.extract.pipeline.Extractor` size: int The size that the aligned face should be created at """ for face in extract_media.detected_faces: face.load_aligned(extract_media.image, size=size, centering="head") face.thumbnail = generate_thumbnail(face.aligned.face, size=96, quality=60) self._post_process.do_actions(extract_media) extract_media.remove_image() faces_count = len(extract_media.detected_faces) if faces_count == 0: logger.verbose("No faces were detected in image: %s", os.path.basename(extract_media.filename)) if not self._verify_output and faces_count > 1: self._verify_output = True
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, centering="head") face.thumbnail = generate_thumbnail(face.aligned.face, size=80, quality=60) return face
def post_edit_trigger(self, frame_index, face_index): """ Update the jpg thumbnail and the viewport thumbnail on a face edit. Parameters ---------- frame_index: int The frame that the face is being set for face_index: int The face index within the frame """ face = self._frame_faces[frame_index][face_index] aligned = AlignedFace(face.landmarks_xy, image=self._globals.current_frame["image"], centering="head", size=96) face.thumbnail = generate_thumbnail(aligned.face, size=96) self._tk_edited.set(True)
def _output_faces(self, filename, image): """ For each frame save out the faces Parameters ---------- filename: str The filename (without the full path) of the current frame image: :class:`numpy.ndarray` The full frame that faces are to be extracted from Returns ------- int The total number of faces that have been extracted """ logger.trace("Outputting frame: %s", filename) face_count = 0 frame_name = os.path.splitext(filename)[0] faces = self._select_valid_faces(filename, image) if not faces: return face_count if self._is_legacy: faces = self._process_legacy(filename, image, faces) for idx, face in enumerate(faces): output = "{}_{}.png".format(frame_name, str(idx)) meta = dict(alignments=face.to_png_meta(), source=dict( alignments_version=self._alignments.version, original_filename=output, face_index=idx, source_filename=filename, source_is_video=self._frames.is_video, source_frame_dims=image.shape[:2])) self._saver.save( output, encode_image(face.aligned.face, ".png", metadata=meta)) if not self._arguments.large and self._is_legacy: face.thumbnail = generate_thumbnail(face.aligned.face, size=96, quality=60) self._alignments.data[filename]["faces"][ idx] = face.to_alignment() face_count += 1 self._saver.close() return face_count
def _set_thumbail(self, filename, frame, frame_index): """ Extracts the faces from the frame and adds to alignments file Parameters ---------- filename: str The filename of the frame within the alignments file frame: :class:`numpy.ndarray` The frame that contains the faces frame_index: int The frame index of this frame in the :attr:`_frame_faces` """ for face_idx, face in enumerate(self._frame_faces[frame_index]): aligned = AlignedFace(face.landmarks_xy, image=frame, centering="head", size=96) face.thumbnail = generate_thumbnail(aligned.face, size=96) self._alignments.thumbnails.add_thumbnail(filename, face_idx, face.thumbnail) with self._pbar["lock"]: self._pbar["pbar"].update(1)
def post_edit_trigger(self, frame_index, face_index): """ Update the jpg thumbnail, the viewport thumbnail, the landmark masks and the aligned face on a face edit. Parameters ---------- frame_index: int The frame that the face is being set for face_index: int The face index within the frame """ face = self._frame_faces[frame_index][face_index] face.load_aligned(None, force=True) # Update average distance face.mask = self._extractor.get_masks(frame_index, face_index) aligned = AlignedFace(face.landmarks_xy, image=self._globals.current_frame["image"], centering="head", size=96) face.thumbnail = generate_thumbnail(aligned.face, size=96) if self._globals.filter_mode == "Misaligned Faces": self._detected_faces.tk_face_count_changed.set(True) self._tk_edited.set(True)