python人脸识别视频教程_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 人脸识别的资料请关注我们其它相关文章!

本文标题: python实现图片,视频人脸识别(dlib版)

本文地址: http://www.cppcns.com/jiaoben/python/365188.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值