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,人脸,识别


猜你喜欢
用 Javascript 验证表单(form)中多选框(checkbox)值
2024-04-10 10:39:14
JavaScript判断变量是否为undefined的两种写法区别
2024-04-19 09:53:50

PHP中error_reporting()函数的用法(修改PHP屏蔽错误)
2023-11-20 01:08:17
详解如何在Apache中运行Python WSGI应用
2021-05-16 05:24:03
ASP代理采集的核心函数代码
2010-01-02 20:43:00
python pandas.DataFrame选取、修改数据最好用.loc,.iloc,.ix实现
2023-07-25 16:29:47
sql 存储过程分页代码 支持亿万庞大数据量
2011-09-30 11:16:46
Python_查看sqlite3表结构,查询语句的示例代码
2021-01-24 22:35:06
解决Jupyter 文件路径的问题
2022-09-10 09:15:59

javascript中声明函数的方法及调用函数的返回值
2024-03-21 23:49:04
使用python批量修改XML文件中图像的depth值
2023-03-05 12:59:06

pandas 强制类型转换 df.astype实例
2022-03-27 04:41:56

Python 使用指定的网卡发送HTTP请求的实例
2022-07-05 05:30:00
Mysql语句快速复习教程(全)
2024-01-26 20:13:37
asp怎么实现中文字符串按声母检索
2010-05-16 21:19:00
使用Python项目生成所有依赖包的清单方式
2022-02-18 19:14:49
详解pyqt中解决国际化tr()函数不起作用的问题
2021-03-31 05:15:56
解决PyCharm不运行脚本,而是运行单元测试的问题
2023-04-12 01:08:53
带中英文翻译功能的收藏夹
2008-07-31 11:33:00
python实现beta分布概率密度函数的方法
2021-08-02 21:39:16
