【dlib人脸检测篇--python(附检测文件下载链接)】

首先在conda创建python3.6的环境,然后使用清华源下载dlib与相关依赖库

pip install dlib==19.7.0 -i  https://pypi.tuna.tsinghua.edu.cn/simple
pip install numpy -i  https://pypi.tuna.tsinghua.edu.cn/simple
pip install opencv-python -i  https://pypi.tuna.tsinghua.edu.cn/simple

pe_predictor_68_face_landmarks.dat是已经训练好的人脸关键点检测器。dlib_face_recognition_resnet_model_v1.dat 是训练好的ResNet人脸识别模型。

detector是dlib训练好的人脸检测器,是基于HOG特征的,也可以是基于resnet深度学习的。

如:shape = landmark_predictor(img,d)

我们想要的特征点全部保存在了shape里面,d是dlib.rectangle(),里面保存着人脸检测矩形的左上和右下坐标,shape.part(i)是第i个特征点

检测的代码:

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

import numpy as np
import cv2
import dlib

detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor('shape_predictor_68_face_landmarks.dat')

# cv2读取图像
img = cv2.imread("1.jpg")

# 取灰度
img_gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)

# 人脸数rects
rects = detector(img_gray, 0)
for i in range(len(rects)):
    landmarks = np.matrix([[p.x, p.y] for p in predictor(img,rects[i]).parts()])
    for idx, point in enumerate(landmarks):
        # 68点的坐标
        pos = (point[0, 0], point[0, 1])
        print(idx,pos)

        # 利用cv2.circle给每个特征点画一个圈,共68个
        cv2.circle(img, pos, 5, color=(0, 255, 0))
        # 利用cv2.putText输出1-68
        font = cv2.FONT_HERSHEY_SIMPLEX
        cv2.putText(img, str(idx+1), pos, font, 0.8, (0, 0, 255), 1,cv2.LINE_AA)

cv2.namedWindow("img", 2)
cv2.imshow("img", img)

效果图如下

 

68个特征点:

 

关于 shape_predictor_68_face_landmarks.dat.bz2检测文件,官网下载贼慢,这里本人上传到csdn,链接如下:https://download.csdn.net/download/qq_35054151/11483794

 

 

不错的链接:https://blog.csdn.net/weixin_39875161/article/details/88073849

眨眼检测:https://www.cnblogs.com/gmhappy/p/9472368.html

参考链接:https://blog.csdn.net/AI_girl/article/details/86165960

https://blog.csdn.net/qq_39438636/article/details/79304130

https://www.cnblogs.com/as3asddd/p/7257820.html

c++:https://blog.csdn.net/qq_34106574/article/details/84022449

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

CVer儿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值