一定要先安装cmake、boost 再安装dlib,否则可能不成功。
安装命令:
pip install cmake
pip install boost
pip install dlib
或选择镜像源提升安装速度:
pip install cmake -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
pip install boost -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
pip install dlib -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
安装成功截图如下:
测试代码:
import dlib
from skimage import io
# 使用特征提取器frontal_face_detector
detector = dlib.get_frontal_face_detector()
# path是图片所在路径
path = "/data/Pictures/"
img = io.imread(path+"34445.png")
# 特征提取器的实例化
dets = detector(img)
print("人脸数:", len(dets))
# 输出人脸矩形的四个坐标点
for i, d in enumerate(dets):
print("第", i, "个人脸d的坐标:",
"left:", d.left(),
"right:", d.right(),
"top:", d.top(),
"bottom:", d.bottom())
# 绘制图片
win = dlib.image_window()
# 清除覆盖
#win.clear_overlay()
win.set_image(img)
# 将生成的矩阵覆盖上
win.add_overlay(dets)
# 保持图像
dlib.hit_enter_to_continue()
输出结果:
人脸数: 1
第 0 个人脸d的坐标: left: 231 right: 355 top: 79 bottom: 203
Hit enter to continue
Process finished with exit code 0
测试结果:
参考:
https://www.jb51.net/article/133576.htm