在人脸检测与人脸识别库中dlib库所谓是非常好的了。检测效果非常ok,下面我们来了解一下这个神奇的库吧!

 第一步我们首先学会安装:dlib ,winds+pytho3.6.5  Windows不支持pip在线安装,所以我们直接下载whl文件在使用pip安装就可以了。dlib安装连接,主要注意的是cmake的安装,在Windows使用必须安装cmake进行编译,因为dlib源码是c写的。dlib进行关键点提取和人脸识别的模型见连接,下面来两个小案例把:

简单人脸检测:

import dlib
import cv2 # 使用 Dlib 的正面人脸检测器 frontal_face_detector
detector = dlib.get_frontal_face_detector() # 图片所在路径
# read image
img = cv2.imread("./img/img_bjn.jpg") # 使用 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) cv2.namedWindow("img", 2)
cv2.imshow("img", img)
cv2.waitKey(0)

特征检测:

import dlib
from skimage import io
import cv2 # 使用 Dlib 的正面人脸检测器 frontal_face_detector
detector = dlib.get_frontal_face_detector() # Dlib 的 68点模型
predictor = dlib.shape_predictor("./model/shape_predictor_68_face_landmarks.dat") # 图片所在路径
img = io.imread("./img/sn.jpg")
# img = cv2.imread("./img/sn.jpg")
img = cv2.resize(img,(1000,600)) # 生成 Dlib 的图像窗口
win = dlib.image_window()
win.set_image(img) # 使用 detector 检测器来检测图像中的人脸
faces = detector(img,1)
print("人脸数:", len(faces),[im for im in faces]) for i, d in enumerate(faces):
print("第", i+1, "个人脸的矩形框坐标:",
"left:", d.left(), "right:", d.right(), "top:", d.top(), "bottom:", d.bottom()) # 使用predictor来计算面部轮廓
shapes = predictor(img, faces[i])
# print([i for i in shapes])
# 绘制面部轮廓
win.add_overlay(shapes) # 绘制矩阵轮廓
win.add_overlay(faces) # 保持图像
dlib.hit_enter_to_continue()

最新文章

  1. Mysql查询——学习阶段
  2. Java将TXT上的数据转换成excel里面
  3. SQL语句来查询今天、昨天、7天内、30天的数据,经典!
  4. start
  5. JavaWeb学习笔记——SAX解析
  6. C++:运算符重载函数之"++"、"--"、"[ ]"、"=="的应用
  7. OC基础 内存管理
  8. CSS3的线性渐变(linear-gradient)
  9. 1113: [Poi2008]海报PLA
  10. Java课程设计 购物车系统(个人博客)
  11. Android Studio 3.0+ Annotation processors must be explicitly declared now
  12. css 文本超出2行就隐藏并且显示省略号
  13. Python2.7-sched
  14. OC MRC之循环引用问题(代码分析)
  15. 38. CentOS-6.3安装配置Tomcat-7
  16. Delphi按名字调用方法高级解决方案
  17. imp与impdp比较
  18. Java入门系列-08-选择结构
  19. sshd 防止暴力破解
  20. Python操作SQLLite(基本操作)

热门文章

  1. 纯原生仿ES6的Object.assign,实现深度合并对象
  2. 『Python Kivy』官方乒乓球游戏示例解析
  3. Linux-Shell脚本编程-学习-5-Shell编程-使用结构化命令-if-then-else-elif
  4. Swiper 常用功能及配置清单
  5. 扩展欧几里得 求ax+by == n的非负整数解个数
  6. 测试理论--branch testing and boundary testing
  7. C#程序中SQL语句作为函数参数形式问题
  8. Top K 算法详解
  9. poi excel导出 xssf 带下拉框
  10. DELPHI控件属性事件说明