1
0
Fork 0
mirror of https://github.com/deepfakes/faceswap synced 2025-06-08 11:53:26 -04:00
faceswap/lib/faces_detect.py

14 lines
477 B
Python

import cv2
from DetectedFace import DetectedFace
# Give right path to the xml file or put it directly in current folder
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
def crop_faces(image):
# Add : cv.EqualizeHist(image, image) ?
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
for (x, y, w, h) in faces:
yield DetectedFace(image[y: y + h, x: x + w], x, w, y, h, None)