def get_landmarks(img, detect_face=True):
""" Return the landmarks of the image """
w, h = img.shape[:2]
# default values
x = 0.08 * w
y = 0.08 * h
w = 0.84 * w
h = 0.84 * h
x, y, w, h = convert_to_long(x, y, w, h)
if detect_face:
rects = cascade.detectMultiScale(img, 1.3, 5)
if len(rects) >= 1:
rects = rects[np.argsort(rects[:, 3])[::-1]]
x, y, w, h = rects[0].astype(long)
x = x.item()
y = y.item()
w = w.item()
h = h.item()
rect = dlib.rectangle(x, y, x + w, y + h)
return np.array([(p.x, p.y) for p in predictor(img, rect).parts()])
评论列表
文章目录