mirror of
https://github.com/deepfakes/faceswap
synced 2025-06-08 11:53:26 -04:00
* port 'face_alignment' from PyTorch to Keras. It works x2 faster, but initialization takes 20secs. 2DFAN-4.h5 and mmod_human_face_detector.dat included in lib\FaceLandmarksExtractor fixed dlib vs tensorflow conflict: dlib must do op first, then load keras model, otherwise CUDA OOM error if face location not found by CNN, its try to find by HOG. removed this: - if face.landmarks == None: - print("Warning! landmarks not found. Switching to crop!") - return cv2.resize(face.image, (size, size)) because DetectedFace always has landmarks * removing DetectedFace.landmarks
19 lines
No EOL
704 B
Python
19 lines
No EOL
704 B
Python
from lib import FaceLandmarksExtractor
|
|
|
|
def detect_faces(frame, model="hog"):
|
|
fd = FaceLandmarksExtractor.extract (frame, True if model == "cnn" else False )
|
|
for face in fd:
|
|
x, y, right, bottom, landmarks = face[0][0], face[0][1], face[0][2], face[0][3], face[1]
|
|
yield DetectedFace(frame[y: bottom, x: right], x, right - x, y, bottom - y, landmarksXY=landmarks)
|
|
|
|
class DetectedFace(object):
|
|
def __init__(self, image=None, x=None, w=None, y=None, h=None, landmarksXY=None):
|
|
self.image = image
|
|
self.x = x
|
|
self.w = w
|
|
self.y = y
|
|
self.h = h
|
|
self.landmarksXY = landmarksXY
|
|
|
|
def landmarksAsXY(self):
|
|
return self.landmarksXY |