python dlib 人脸检测

1. anaconda 安装dlib库:

安装命令:https://anaconda.org/conda-forge/dlib

打开Anaconda Prompt:输入

conda install -c conda-forge dlib=19.9

等待安装完成即可;

2. 测试示例

方法1:基于Hog-SVM人脸检测器

方法2:基于深度卷积神经网络实现的人脸检测

# -*- coding: utf-8 -*-
"""
Created on Mon Jun 17 16:51:46 2019

@author: zfjuan
"""

import cv2
import dlib

img = cv2.imread('.\\image\\keliamoniz1.jpg');

'''
#方法1:
# 使用 Dlib 的正面人脸检测器 frontal_face_detector
detector = dlib.get_frontal_face_detector()
# 使用 detector 检测器来检测图像中的人脸
# use detector of Dlib to detector faces
faces = detector(img, 1)
print("人脸数 / Faces in all: ", len(faces))
# Traversal every face
for i, d in enumerate(faces):
    print("第", i+1, "个人脸的矩形框坐标:",
          "left:", d.left(), "right:", d.right(), "top:", d.top(), "bottom:", d.bottom())
    cv2.rectangle(img, tuple([d.left(), d.top()]), tuple([d.right(), d.bottom()]), (0, 255, 255), 2)
    
'''

#方法2
hog_face_detector = dlib.cnn_face_detection_model_v1('.\\data\\mmod_human_face_detector.dat')
face_rects = hog_face_detector(img, 0)

for feacRect in face_rects:
    cv2.rectangle(img,  tuple([feacRect.rect.left(), feacRect.rect.top()]), tuple([feacRect.rect.right(), feacRect.rect.bottom()]), (0, 255, 255), 2)


cv2.namedWindow("img", 1)
cv2.imshow("img", img)
cv2.waitKey(0)
cv2.destroyAllWindows()

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

JoannaJuanCV

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

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

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

打赏作者

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

抵扣说明:

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

余额充值