标题:
用python3.6在电脑上实现用摄像头来人脸识别源程序
[打印本页]
作者:
曾钦昶
时间:
2019-5-18 22:03
标题:
用python3.6在电脑上实现用摄像头来人脸识别源程序
在这里,我用了anaconda,OpenCV,python3.6来实现代码的,代码在附件中,可以自己下载了,自己试试
python源程序如下:
# -*- coding: UTF-8 -*-
import face_recognition
import cv2
import os
# 这是一个超级简单(但很慢)的例子,在你的网络摄像头上实时运行人脸识别
# PLEASE NOTE: This example requires OpenCV (the `cv2` library) to be installed only to read from your webcam.
# 请注意:这个例子需要安装OpenCV
# 具体的演示。如果你安装它有困难,试试其他不需要它的演示。
# 得到一个参考的摄像头# 0(默认)
video_capture = cv2.VideoCapture(0)
# 加载示例图片并学习如何识别它。
path ="images"#在同级目录下的images文件中放需要被识别出的人物图
total_image=[]
total_image_name=[]
total_face_encoding=[]
for fn in os.listdir(path): #fn 表示的是文件名
total_face_encoding.append(face_recognition.face_encodings(face_recognition.load_image_file(path+"/"+fn))[0])
fn=fn[:(len(fn)-4)]#截取图片名(这里应该把images文件中的图片名命名为为人物名)
total_image_name.append(fn)#图片名字列表
while True:
# 抓取一帧视频
ret, frame = video_capture.read()
# 发现在视频帧所有的脸和face_enqcodings
face_locations = face_recognition.face_locations(frame)
face_encodings = face_recognition.face_encodings(frame, face_locations)
# 在这个视频帧中循环遍历每个人脸
for (top, right, bottom, left), face_encoding in zip(face_locations, face_encodings):
# 看看面部是否与已知人脸相匹配。
for i,v in enumerate(total_face_encoding):
match = face_recognition.compare_faces([v], face_encoding,tolerance=0.5)
name = "Unknown"
if match[0]:
name = total_image_name[i]
break
# 画出一个框,框住脸
cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2)
# 画出一个带名字的标签,放在框下
cv2.rectangle(frame, (left, bottom - 35), (right, bottom), (0, 0, 255), cv2.FILLED)
font = cv2.FONT_HERSHEY_DUPLEX
cv2.putText(frame, name, (left + 6, bottom - 6), font, 1.0, (255, 255, 255), 1)
# 显示结果图像
cv2.imshow('Video', frame)
# 按q退出
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# 释放摄像头中的流
video_capture.release()
cv2.destroyAllWindows()
复制代码
以上代码下载:
人脸识别.zip
(1.32 KB, 下载次数: 214)
2019-5-18 22:00 上传
点击文件名下载附件
下载积分: 黑币 -5
作者:
放眼天下
时间:
2019-10-25 10:58
这个怎么么用啊...电脑上自带的摄像头可以吗
作者:
bunny0928
时间:
2019-10-27 08:52
想試一試
作者:
QDMLIT
时间:
2019-10-31 15:58
谢谢你的辛勤劳动
作者:
鹏博士PBs
时间:
2020-4-24 17:38
楼上的人脸识别face_recognition的定义是否需要更改
作者:
xnhtao
时间:
2020-5-12 08:43
人脸识别这么简单吗?
作者:
xintiandi
时间:
2020-5-13 09:26
不错。支持一下,现在python是主流了。
作者:
lirizhi
时间:
2020-5-25 10:28
不错。支持一下。
作者:
vvcc
时间:
2020-6-1 09:16
可以试试
作者:
MikeCai
时间:
2020-6-9 09:16
thanks you for your sharing
作者:
好好学习1999
时间:
2021-2-1 13:29
放眼天下 发表于 2019-10-25 10:58
这个怎么么用啊...电脑上自带的摄像头可以吗
同问 用电脑自带的摄像头可以吗
作者:
dzc3458
时间:
2021-11-2 09:29
xnhtao 发表于 2020-5-12 08:43
人脸识别这么简单吗?
都是别人写好了的库,真实的人脸识别难得多
作者:
zjnbzm
时间:
2023-10-8 10:40
谢谢分享一下这个程序,谢谢楼主!
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1