栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

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

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

图片人脸检测

#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就好很多,基本看不出来;

以上就是python实现图片,视频人脸识别(dlib版)的详细内容,更多关于python 人脸识别的资料请关注考高分网其它相关文章!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/16336.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号