换脸步骤:
# coding=utf-8
import cv2
import dlib
import os
import numpy as np
import glob
class NoFace(Exception):
pass
class Facechanger(object):
def __init__(self,which_predictor = '68',windowname = ' exchange face'):
self.current_path = os.getcwd()
self.predictor_68_path = self.current_path + "\shape_predictor_68_face_landmarks.dat"
self.predictor_5_points_path = self.current_path + "\shape_predictor_5_face_landmarks.dat"
self.detector = dlib.get_frontal_face_detector()
self.predictor= dlib.shape_predictor(self.predictor_68_path)
self.SCALE_FACTOR = 1
self.FEATHER_AMOUNT = 11
self.COLOUR_CORRECT_BLUR_FRAC = 0.6
self.FACE_POINTS = list(range(17, 68))
self.MOUTH_POINTS = list(range(48, 61))
self.RIGHT_BROW_POINTS = list(range(17, 22))
self.LEFT_BROW_POINTS = list(range(22, 27))
self.RIGHT_EYE_POINTS = list(range(36, 42))
self.LEFT_EYE_POINTS = list(range(42, 48))
self.NOSE_POINTS = list(range(27, 35))
self.JAW_POINTS = list(range(0, 17))
self.ALIGN_POINTS = (self.LEFT_BROW_POINTS + self.RIGHT_EYE_POINTS + self.LEFT_EYE_POINTS +
self.RIGHT_BROW_POINTS + self.NOSE_POINTS + self.MOUTH_POINTS)
self.OVERLAY_POINTS = [self.LEFT_BROW_POINTS + self.RIGHT_EYE_POINTS + self.LEFT_EYE_POINTS +
self.RIGHT_BROW_POINTS + self.NOSE_POINTS + self.MOUTH_POINTS]