python opencv dlib换脸代码
代码语言:python
所属分类:人工智能
代码描述:python opencv dlib换脸代码,利用开源的opencv及dlib来实现
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
#!/usr/local/python3/bin/python3 # -*- coding: utf-8 -* import cv2 import numpy as np import dlib img = cv2.imread("/data/wwwroot/default/asset/katrina-kaif.jpg") img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) mask = np.zeros_like(img_gray) detector = dlib.get_frontal_face_detector() predictor = dlib.shape_predictor("/data/wwwroot/default/model/shape_predictor_68_face_landmarks.dat") faces = detector(img_gray) for face in faces: landmarks = predictor(img_gray, face) landmarks_points = [] for n in range(0, 68): x = landmarks.part(n).x y = landmarks.part(n).y landmarks_points.append((x, y)) #cv2.circle(img, (x, y), 3, (0, 0, 255), -1) points = np.array(landmarks_points, np.int32) convexhull = cv2.convexHull(points) #cv2..........完整代码请登录后点击上方下载按钮下载查看
网友评论0