mirror of
https://github.com/deepfakes/faceswap
synced 2025-06-08 03:26:47 -04:00
* Add preview functionality to effmpeg. (#435) * Add preview functionality to effmpeg. effmpeg tool: Preview for actions that have a video output now available. Preview does not work when muxing audio. * Model json unicode fix1 (#443) * fixed Windows 10 path error while loading weights * - fixed TypeError: the JSON object must be str, not 'bytes' with OriginalHighRes Model * MTCNN Extractor and Extraction refactor (#453) * implement mtcnn extractor * mtcnn refactor and vram management changes * cli arguments update for mtcnn/dlib split * Add mtcnn models to gitignore * Change multiprocessing on extract * GUI changes to handle nargs defaults * Early exit bugfix (#455) * Fix extract early termination bug * Fix extract early exit bug * Multi face detection bugfix (#456) * Multi face extraction fix * Original high res cleanup 1 (#457) * slight model re-factoring - removed excess threading code - added random kernel initialization to dense layer * Slight OriginalHighRes re-factoring an code cleanup
41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
#!/usr/bin python3
|
|
""" Face and landmarks detection for faceswap.py """
|
|
|
|
from lib import face_alignment
|
|
|
|
|
|
def detect_faces(frame, detector, verbose, rotation=0, mtcnn_kwargs=None):
|
|
""" Detect faces and draw landmarks in an image """
|
|
face_detect = face_alignment.Extract(frame,
|
|
detector,
|
|
mtcnn_kwargs,
|
|
verbose)
|
|
for face in face_detect.landmarks:
|
|
ax_x, ax_y = face[0][0], face[0][1]
|
|
right, bottom = face[0][2], face[0][3]
|
|
landmarks = face[1]
|
|
|
|
yield DetectedFace(frame[ax_y: bottom, ax_x: right],
|
|
rotation,
|
|
ax_x,
|
|
right - ax_x,
|
|
ax_y,
|
|
bottom - ax_y,
|
|
landmarksXY=landmarks)
|
|
|
|
|
|
class DetectedFace(object):
|
|
""" Detected face and landmark information """
|
|
def __init__(self, image=None, r=0, x=None,
|
|
w=None, y=None, h=None, landmarksXY=None):
|
|
self.image = image
|
|
self.r = r
|
|
self.x = x
|
|
self.w = w
|
|
self.y = y
|
|
self.h = h
|
|
self.landmarksXY = landmarksXY
|
|
|
|
def landmarks_as_xy(self):
|
|
""" Landmarks as XY """
|
|
return self.landmarksXY
|