python实现图片,视频人脸识别(dlib版)

作者:https://github.com/LeonPython/faceai/blob/master/doc/videoOpenCV.md 时间:2023-03-28 14:35:19 

图片人脸检测


#coding=utf-8

import cv2
import dlib

path = "img/meinv.png"
img = cv2.imread(path)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

#人脸分类器
detector = dlib.get_frontal_face_detector()
# 获取人脸检测器
predictor = dlib.shape_predictor(
 "C:\\Python36\\Lib\\site-packages\\dlib-data\\shape_predictor_68_face_landmarks.dat"
)

dets = detector(gray, 1)
for face in dets:
 shape = predictor(img, face) # 寻找人脸的68个标定点
 # 遍历所有点,打印出其坐标,并圈出来
 for pt in shape.parts():
   pt_pos = (pt.x, pt.y)
   cv2.circle(img, pt_pos, 2, (0, 255, 0), 1)
 cv2.imshow("image", img)

cv2.waitKey(0)
cv2.destroyAllWindows()

视频人脸检测


# coding=utf-8
import cv2
import dlib

detector = dlib.get_frontal_face_detector() #使用默认的人类识别器模型

def discern(img):
 gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
 dets = detector(gray, 1)
 for face in dets:
   left = face.left()
   top = face.top()
   right = face.right()
   bottom = face.bottom()
   cv2.rectangle(img, (left, top), (right, bottom), (0, 255, 0), 2)
   cv2.imshow("image", img)

cap = cv2.VideoCapture(0)
while (1):
 ret, img = cap.read()
 discern(img)
 if cv2.waitKey(1) & 0xFF == ord('q'):
   break

cap.release()
cv2.destroyAllWindows()

那么,OpenCV和Dlib的视频识别对比,有两个地方是不同的:

1.Dlib模型识别的准确率和效果要好于OpenCV;

2.Dlib识别的性能要比OpenCV差,使用视频测试的时候Dlib有明显的卡顿,但是OpenCV就好很多,基本看不出来;

来源:https://github.com/LeonPython/faceai/blob/master/doc/videoOpenCV.md

标签:python,人脸,识别
0
投稿

猜你喜欢

  • 带你深入了解MySQL数据库系统参数的优化

    2009-03-06 17:58:00
  • CSS hack:区分IE6,IE7,firefox

    2007-12-23 10:25:00
  • 20个Javascript手风琴折叠菜单

    2009-10-12 12:09:00
  • ThinkPHP CURD方法之limit方法详解

    2023-11-15 03:58:00
  • 微信小程序简单的canvas裁剪图片功能详解

    2023-08-24 07:49:20
  • SQL Server中如何快速获取表的记录总数

    2008-12-05 15:59:00
  • DataReader深入解析:持续更新

    2023-07-11 06:24:08
  • asp如何获知页面上的图象的实际尺寸?

    2009-11-24 20:50:00
  • Python sublime安装及配置过程详解

    2021-07-06 19:57:47
  • ASP应用:用stream读文件

    2007-09-24 13:33:00
  • 数据库中identity字段不必是系统产生的唯一值 性能优化方法(新招)

    2011-09-30 11:26:06
  • 剖析网页设计中的几何圆

    2010-10-19 12:27:00
  • 微软建议的ASP性能优化28条守则(5)

    2008-02-27 13:54:00
  • IE10增强对HTML5和CSS3的支持

    2011-09-16 20:16:28
  • 破解 屏蔽 防框架代码 top.location != self.location

    2008-11-27 12:59:00
  • oracle学习笔记(二)

    2012-01-05 18:59:20
  • [xhtml+css实例]不规则导航的制作

    2008-04-04 18:11:00
  • python3的pip路径在哪

    2023-01-27 14:15:39
  • Navicat for MySQL 与 MySQL-Front比较

    2009-02-12 17:33:00
  • asp 解析一个xml文件的公用函数集合

    2008-02-29 13:40:00
  • asp之家 网络编程 m.aspxhome.com