81个人脸关键点检测

之前运行过Dlib,主要是做了68个人脸关键点的检测,其对应的68个人脸关键点如下图:

 ​https://i-blog.csdnimg.cn/blog_migrate/b36fe0edd781dcdd2e718e2fe1a8d7af.png

 其中关于dlib的68个点的使用可参考:https://blog.csdn.net/xingchenbingbuyu/article/details/51116354

本文讲的demo是在dlib基础上的扩展;

项目地址:https://github.com/codeniko/shape_predictor_81_face_landmarks

该项目实现对于给的的图像(pic或者视频流的帧)做81个人脸特征点检测,训练过程类似dlib的68个点,作者加了前额部分的13个点。对于头部检测或者针对那个区域做图像处理来说精度提高了。如作者在额头添了个帽子的操作~

placing a hat on someone's head.

这13个点的提取,作者是参考了patrikhuber的eos项目: https://github.com/codeniko/eos.

作者并使用了Surrey Face Model 

以下是作者原话:

“I made the modifications here, then ran it on the entire ibug large database of images to overwrite each image's 68 landmark coordinates with my 81 landmark coordinates. From here, the training for the shape predictor model can proceed using http://dlib.net/train_shape_predictor.py.html  ”

可翻墙看下作者运行了该项目的demo视频  https://www.youtube.com/watch?v=mDJrASIB1T0

以下是81个特征点的分布,其中0~67是dlib的68个点,68~80是作者后加的13个点;

 ​https://i-blog.csdnimg.cn/blog_migrate/ac7104f2a603a9259a12c70445180189.png

下载了项目代码后,切到项目路径下,我用的是anaconda 环境,运行其中的webcam_record.py脚本,指令如下:

python webcam_record.py
 ​https://i-blog.csdnimg.cn/blog_migrate/620b1bc73e336bab991228c8c0cd433b.png

运行如上代码,会实时捕获摄像头,并做人脸关键点检测,结果如下:

 ​https://i-blog.csdnimg.cn/blog_migrate/6f4e7c644ef1d9393de1ae0e6c44c530.png

检测实时性是真的很好,完全cpu运行的,对于小的图像人脸检测也是不错的,不过在人脸侧向角度稍大一些就会检不出了~
猜猜我手机中的女明星是谁~~~
其中脚本源码内容如下(跟dlib基础一样):

webcam_record.py
import sys
import os
import dlib
import glob
from skimage import io
import numpy as np
import cv2
 
 
cap = cv2.VideoCapture(0)    #读取摄像头
fourcc = cv2.VideoWriter_fourcc(*'XVID')   #生成视频文件的编码形式
 
out = cv2.VideoWriter('output.avi',fourcc, 20.0, (1280, 720)) #输出视频的参数信息
 
predictor_path = 'shape_predictor_81_face_landmarks.dat'   #官方训练好的模型文件
 
detector = dlib.get_frontal_face_detector()  #使用dlib自带的frontal_face_detector作为我们的人脸提取器
predictor = dlib.shape_predictor(predictor_path) 
#2.使用官方提供的模型构建特征提取器
 
while(cap.isOpened()):
    ret, frame = cap.read()
    frame = cv2.flip(frame, 1)  #图像水平翻转
    dets = detector(frame, 0) #3.使用detector进行人脸检测 dets为返回的结果
    for k, d in enumerate(dets):
        shape = predictor(frame, d) #5.使用predictor进行人脸关键点识别
        landmarks = np.matrix([[p.x, p.y] for p in shape.parts()])
        for num in range(shape.num_parts):
            cv2.circle(frame, (shape.parts()[num].x, shape.parts()[num].y), 3, (0,255,0), -1)  #6.绘制特征点
    cv2.imshow('frame', frame)
    out.write(frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        print("q pressed")
        break
 
 
cap.release()
out.release()
 
cv2.destroyAllWindows()
 
 
你事先需要安装一些库,使用pip

pip cmake,opencv-python, dlib

cmake是用于编译dlib库的~

enjoy !
--------------------- 
作者:ciky奇 
来源:CSDN 
原文:https://blog.csdn.net/c20081052/article/details/88854512 
版权声明:本文为博主原创文章,转载请附上博文链接!

https://blog.csdn.net/yh0vlde8vg8ep9vge/article/details/88638013

https://download.csdn.net/download/sx1367534246/10398250

https://blog.csdn.net/hongbin_xu/article/details/78443289

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值