def to_detected_face(image, dlib_rects): """ Convert list of dlib rectangles to a list of DetectedFace objects and add the cropped face """ retval = list() for d_rect in dlib_rects: if not isinstance(d_rect, dlib.rectangle): retval.append(list()) continue detected_face = DetectedFace() detected_face.from_dlib_rect(d_rect) detected_face.image_to_face(image) retval.append(detected_face) return retval
def align_face(self, faces, align_eyes, size, filename): """ Align the detected face and add the destination file path """ final_faces = list() image = faces["image"] landmarks = faces["landmarks"] detected_faces = faces["detected_faces"] for idx, face in enumerate(detected_faces): detected_face = DetectedFace() detected_face.from_dlib_rect(face, image) detected_face.landmarksXY = landmarks[idx] detected_face.load_aligned(image, size=size, align_eyes=align_eyes) final_faces.append({"file_location": self.output_dir / Path(filename).stem, "face": detected_face}) faces["detected_faces"] = final_faces
def detect_faces(self, load_queue, filename, image): """ Extract the face from a frame (If alignments file not found) """ inp = {"filename": filename, "image": image} load_queue.put(inp) faces = next(self.extractor.detect_faces()) landmarks = faces["landmarks"] detected_faces = faces["detected_faces"] final_faces = list() for idx, face in enumerate(detected_faces): detected_face = DetectedFace() detected_face.from_dlib_rect(face) detected_face.landmarksXY = landmarks[idx] final_faces.append(detected_face) return final_faces
def align_face(faces, align_eyes, size, padding=48): """ Align the detected face """ final_faces = list() image = faces["image"] landmarks = faces["landmarks"] detected_faces = faces["detected_faces"] for idx, face in enumerate(detected_faces): detected_face = DetectedFace() detected_face.from_dlib_rect(face, image) detected_face.landmarksXY = landmarks[idx] detected_face.frame_dims = image.shape[:2] detected_face.load_aligned(image, size=size, padding=padding, align_eyes=align_eyes) final_faces.append(detected_face) faces["detected_faces"] = final_faces
def to_detected_face(image, dlib_rects): """ Convert list of dlib rectangles to a list of DetectedFace objects and add the cropped face """ retval = list() for d_rect in dlib_rects: if not isinstance( d_rect, dlib.rectangle): # pylint: disable=c-extension-no-member retval.append(list()) continue detected_face = DetectedFace() detected_face.from_dlib_rect(d_rect) detected_face.image_to_face(image) detected_face.frame_dims = image.shape[:2] retval.append(detected_face) return retval