1. 开发环境
Python : 3.6.5
Dlib : 19.7
2. 简介
利用 Dlib 的 get_frontal_face_detector ( 正向人脸检测器),进行人脸检测,绘制人脸外部矩形框
3. 代码
face_detector_remark.py
# -*- coding: utf-8 -*-
import dlib
from skimage import io
import os
import glob
#获取人脸检测器
detector = dlib.get_frontal_face_detector()
#获取当前路径
current_path = os.getcwd()
#绘制图片
win = dlib.image_window()
#循环检测当前目录下的jpg图片
for img_path in glob.glob(os.path.join(current_path,"*.jpg")):
#读取图片
img = io.imread(img_path)
#使用detector进行对图片进行检测
dets = detector(img,1)
#打印人脸数量
print("number of faces detected:{}".format(len(dets)))
# 清除覆盖
win.clear_overlay()
#将图片显示到窗口
win.set_image(img)
#绘制检测到的人脸框
win.add_overlay(dets)
#等待回车
dlib.hit_enter_to_continue()</