人脸关键点显示

效果图:
在这里插入图片描述

补充:下载shape_predictor_68_face_landmarks.dat
补充:我用pip方法下载失败有几个库,所以后来用的海龟编辑器里面的。

# -*- coding: utf-8 -*-

import dlib #dlib
import numpy
from skimage import io  # scikit-image
import cv2  # opencv-python

predictor_path = "D:\BaiduNetdiskDownload\shape_predictor_68_face_landmarks\shape_predictor_68_face_landmarks.dat"
#faces_path = "cl.jpg"  # 
faces_path = "./xinqing/8.jpg"  

'''加载人脸检测器、加载官方提供的模型构建特征提取器'''
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor(predictor_path)

win = dlib.image_window()
img = io.imread(faces_path)

win.clear_overlay()
win.set_image(img)

dets = detector(img, 1)
print("Number of faces detected: {}".format(len(dets)))

for k, d in enumerate(dets):
    shape = predictor(img, d)
    landmark = numpy.matrix([[p.x, p.y] for p in shape.parts()])
    print("face_landmark:")
    print (landmark)  # 打印关键点矩阵
    win.add_overlay(shape)  #绘制特征点
    for idx, point in enumerate(landmark):
        pos = (point[0, 0], point[0, 1])
        cv2.putText(img, str(idx), pos, fontFace=cv2.FONT_HERSHEY_SCRIPT_SIMPLEX,
                    fontScale=0.3, color=(0, 255, 0))
        # cv2.circle(img, pos, 3, color=(0, 255, 0))
    win.set_image(img)

dlib.hit_enter_to_continue()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值