Dlib人脸特征点检测

前言

Dlib库的使用。


一、Dlib是什么?

Dlib由C++编写,提供了和机器学习、数值计算、图模型算法、图像处理等领域相关的一系列功能。详细功能可以登录Dlib官网查看,我具体只使用了Dlib中对于图像处理部分。同时,与许多开源项目不同,该项目为每个类和功能提供完整而精确的文档,可以大大的降低我们使用的难度。

Dlib对于图像处理的应用
可以在Dlib官网对标注的地方进行解读,本文不详细描述。
关于预测训练的模型下载:
http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2

百度网盘链接:shape_predictor_68_face_landmarks.rar

提取码:gnab

二、使用步骤

1.Dlib使用

pip install dlib==19.6.1

2.使用Dlib,可以查看Dlib中关于图像处理的实例CNN Face DetectorFace DetectorFace Landmark DetectionFace RecognitionTrain Shape Predictor

import dlib
import cv2
import os
import numpy as np
from PIL import Image
import imutils
from imutils import face_utils
'''shape_predictor_68_face_landmarks.dat在文章开头分享的百度云链接下载'''
face_landmark_path = 'D:\\WorkPlace\\Python\\test1\\Head_Pose\\shape_predictor_68_face_landmarks.dat'

detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor(face_landmark_path)

def face_recognition(img):
    face_rects = detector(img, 0)
    print(len(face_rects))
    result = []
    for index,face in enumerate(face_rects):
        shape = predictor(img, face_rects[index])
        shape = face_utils.shape_to_np(shape)
        for (x, y) in shape:
            cv2.circle(img, (x, y), 1, (0, 0, 255), -1)

def main():
    image = cv2.imread("D:\\test\\my\\3.jpg")
    try:
         image.shape
    except:
        print("can not read image")
        return 
    image = imutils.resize(image, width=640,height=480) 
    shape = face_recognition(image)
    cv2.imshow("image",image)
    cv2.waitKey(0)
    
if __name__ == '__main__':
    main()

三、效果图

图为使用Dlib进行人脸特征点检测结果图:
人脸特征点检测效果图

图为使用Dlib进行人脸特征点位置和下标:

Dlib检测的68个点的位置和对应的下标


总结

我对于CASIA-FaceV5 人脸数据集抽取了500张人脸图像进行测试,提取成功率约为99%。Dlib的使用既方便有有高识别率,可以为后续对于头部姿态估计提供准确的人脸特征点坐标值,从而使结果更加精确。
  • 3
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值