1 Star 0 Fork 0

sesepp/face-frontalization

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
facial_feature_detector.py 1.24 KB
一键复制 编辑 原始数据 按行查看 历史
Douglas 提交于 2016-02-21 13:46 . Fixing dlib weights download path
__author__ = 'Douglas'
import dlib
import os
import numpy as np
this_path = os.path.dirname(__file__)
def _shape_to_np(shape):
xy = []
for i in range(68):
xy.append((shape.part(i).x, shape.part(i).y,))
xy = np.asarray(xy, dtype='float32')
return xy
def get_landmarks(img):
# if not automatically downloaded, get it from:
# http://sourceforge.net/projects/dclib/files/dlib/v18.10/shape_predictor_68_face_landmarks.dat.bz2
predictor_path = this_path + "/dlib_models/shape_predictor_68_face_landmarks.dat"
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor(predictor_path)
lmarks = []
dets = detector(img, 1)
print("Number of faces detected: {}".format(len(dets)))
shapes = []
for k, det in enumerate(dets):
shape = predictor(img, det)
shapes.append(shape)
xy = _shape_to_np(shape)
lmarks.append(xy)
lmarks = np.asarray(lmarks, dtype='float32')
# display_landmarks(img, dets, shapes)
return lmarks
def display_landmarks(img, dets, shapes):
win = dlib.image_window()
win.clear_overlay()
win.set_image(img)
for shape in shapes:
win.add_overlay(shape)
win.add_overlay(dets)
dlib.hit_enter_to_continue()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/sesepp/face-frontalization.git
git@gitee.com:sesepp/face-frontalization.git
sesepp
face-frontalization
face-frontalization
master

搜索帮助