mirror of
https://github.com/deepfakes/faceswap
synced 2025-06-08 20:13:52 -04:00
* Making Models as plugins * Do not reload model on each image #39 + Adding FaceFilter #53 * Adding @lukaville PR for #43 and #44 (possibly) * Training done in a separate thread * Better log for plugin load * Adding a prefetch to train.py #49 (Note that we prefetch 2 batches of images, due to the queue behavior) + More compact logging with verbose info included * correction of DirectoryProcessor signature * adding missing import * Convert with parallel preprocessing of files * Added coverage var for trainer Added a var with comment. Feel free to add it as argument * corrections * Modifying preview and normalization of image + correction * Cleanup
34 lines
1.2 KiB
Python
34 lines
1.2 KiB
Python
import dlib
|
|
import face_recognition
|
|
import face_recognition_models
|
|
|
|
def detect_faces(frame):
|
|
face_locations = face_recognition.face_locations(frame)
|
|
landmarks = _raw_face_landmarks(frame, face_locations)
|
|
|
|
for ((y, right, bottom, x), landmarks) in zip(face_locations, landmarks):
|
|
yield DetectedFace(frame[y: bottom, x: right], x, right - x, y, bottom - y, landmarks)
|
|
|
|
# Copy/Paste (mostly) from private method in face_recognition
|
|
predictor_68_point_model = face_recognition_models.pose_predictor_model_location()
|
|
pose_predictor = dlib.shape_predictor(predictor_68_point_model)
|
|
|
|
def _raw_face_landmarks(face_image, face_locations):
|
|
face_locations = [_css_to_rect(face_location) for face_location in face_locations]
|
|
return [pose_predictor(face_image, face_location) for face_location in face_locations]
|
|
|
|
def _css_to_rect(css):
|
|
return dlib.rectangle(css[3], css[0], css[1], css[2])
|
|
# end of Copy/Paste
|
|
|
|
class DetectedFace(object):
|
|
def __init__(self, image, x, w, y, h, landmarks):
|
|
self.image = image
|
|
self.x = x
|
|
self.w = w
|
|
self.y = y
|
|
self.h = h
|
|
self.landmarks = landmarks
|
|
|
|
def landmarksAsXY(self):
|
|
return [(p.x, p.y) for p in self.landmarks.parts()]
|