代码拉取完成,页面将自动刷新
__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()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。