dlib库中内置两种人脸检测方法
一个是采用HOG(方向梯度直方图)+线性支持向量机;另一种是Max-Margin (MMOD) CNN方式;
第一种方式就精度来讲没有第二种方式更准确,但是效率高于第二种,不过就目前的硬件条件来说,如果上gpu第二种的效率也是飞快(支持nvidia gpu)。
一、需要安装的包
pip install opencv-contrib-python
pip install dlib
二、使用HOG + Linear SVM检测人脸
import argparse
import imutils
import time
import dlib
import cv2
def convert_and_trim_bb(image, rect):
# extract the starting and ending (x, y)-coordinates of the
# bounding box
startX = rect.left()
startY = rect.top()
endX = rect.right()
endY = rect.bottom()
# ensure the bounding box coordinates fall within the spa