dlib人脸识别

dlib的安装(windows)

  • 安装cmake,在官网下载最新的zar,然后解压,添加环境变量,即可。
  • 安装dlib,pip install dlib
    注意:要先安装好anaconda 和 VS2017

dlib人脸识别例子

import dlib
cnn_face_detector = dlib.cnn_face_detection_model_v1("mmod_human_face_detector.dat")#dat为下载的预训练模型

f = "./data/400_3.bmp"#图片
img = dlib.load_rgb_image(f)
dets = cnn_face_detector(img,1)

print("Num of faces detected: {}".format(len(dets)))
for i, d in enumerate(dets):
    print("detection {}: left:{} top:{} right:{} bottom:{} confidence:{}".format(
    i, d.rect.left(), d.rect.top(), d.rect.right(), d.rect.bottom(), d.confidence))

rects = dlib.rectangles()
rects.extend([d.rect for d in dets])
#显示窗口
win = dlib.image_window()
win.clear_overlay()
win.set_image(img)
win.add_overlay(rects)
dlib.hit_enter_to_continue()

dlib人脸识别

参考链接

官网: cnn_face_detector