美文网首页
利用dlib库进行人脸检测

利用dlib库进行人脸检测

作者: Yankee_13 | 来源:发表于2018-12-17 20:33 被阅读0次

一、dlib的使用

dlib需要预先的安装
①安装Python还是推荐3.5
②下载dlib的安装包
https://pypi.python.org/pypi/dlib/18.17.100
选择匹配的版本,dlib-18.17.100-cp35-none-win_amd64.whl(md5)
③通过命令pip install dlib-18.17.100-cp35-none-win_amd64.whl进行安装

二、dlib中的人脸检测

def detect_face(path):
  detector=dlib.get_frontal_face_detector()
  img=cv2.imread(path)
  RGB_img=cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
  #由于opencv中读取的图片为BGR通道,需要转为RGB通道,再利用detector
  faces=detector(RGB_img,1)

如果没有检测到人脸,可以用如下代码来判断

if len(faces)==0:

三、获取检测结果

for idx,face in enumerate(faces):
        left=face.left()
        right=face.right()
        top=face.top()
        bottom=face.bottom()

四、opencv-python的两个记录

1.快速分割图像通道

(B,G,R)=cv2.split(img)

2.获取图像大小

shape=img.shape
height=shape[0]
weight=shape[1]

3.裁剪图片指定区域

Roi_img=img[top:bottom,left:right]

直接这样即可,不必分割图像通道

相关文章

网友评论

      本文标题:利用dlib库进行人脸检测

      本文链接:https://www.haomeiwen.com/subject/euxhkqtx.html