# coding: utf-8
# ================================
# 人脸样本录入环节
# SEU-PR // R.YY & Z.HF & Z.X
# ================================
import cv2
import PIL.Image
from PIL import ImageTk
from tkinter import *
from tkinter import filedialog, messagebox
import json
import face_detection as FD
from time import time
TARGET_SIZE = (100, 100)
howmany = 0
detected = []
# 摄像头捕获方式
camera = cv2.VideoCapture(0) # 摄像头
current_status = 'none'
camera_looper = None
def capture_camera():
global camera, camera_looper, detected, howmany
if not camera.isOpened():
camera = cv2.VideoCapture(0) # 摄像头
status, frame = camera.read()
if status:
cv2.waitKey(10)
(res, howmany, detected) = FD.detect_face_for_manager(frame)
label_faceCount.config(text='当前人脸数:' + str(howmany))
res = cv2.resize(res, (640, int(640. / res.shape[1] * res.shape[0])))
res = cv2.cvtColor(res, cv2.COLOR_BGR2RGBA)
res_pil = PIL.Image.fromarray(res)
res_tk = ImageTk.PhotoImage(image=res_pil)
display_area.imgtk = res_tk
display_area.config(image=res_tk, width=res.shape[1], height=res.shape[0])
camera_looper = root.after(1, capture_camera) # 反复更新当前帧
# 本地文件方式
def capture_file(path: str):
global detected, howmany
if camera.isOpened() and camera_looper:
root.after_cancel(camera_looper)
camera.release()
img = cv2.imread(path)
(res, howmany, detected) = FD.detect_face_for_manager(img, int(img.shape[0] / 80) + 1)
label_faceCount.config(text='当前人脸数:' + str(howmany))
res = cv2.resize(res, (640, int(640. / res.shape[1] * res.shape[0])))
res = cv2.cvtColor(res, cv2.COLOR_BGR2RGBA)
res_pil = PIL.Image.fromarray(res)
res_tk = ImageTk.PhotoImage(image=res_pil)
display_area.imgtk = res_tk
display_area.config(image=res_tk, width=res.shape[1], height=res.shape[0])
def ask_open_file():
path = filedialog.askopenfilename(title='打开图片...', filetypes=[('PNG Image', '*.png'), ('JPG Image', '*.jpg')])
capture_file(path)
def save_sample():
global detected, howmany
if howmany != 1:
messagebox.showerror('错误', '当前人脸数不为1!')
return
face_gray = cv2.resize(detected[0], TARGET_SIZE)
name = input_label.get()
fp = open('./dataset/manager.json', 'r')
json_content = json.load(fp)
fp.close()
total = int(json_content['total'])
total += 1
json_content['total'] = total
fp = open('./dataset/manager.json', 'w')
json.dump(json_content, fp)
fp.close()
filename = str(total) + '-' + name
save_path = './dataset/train/' + filename + '.png'
cv2.imwrite(save_path, face_gray)
messagebox.showinfo('录入成功', '录入成功!')
root = Tk()
root.title("人脸样本录入 - [SEU-PR]R.YY, Z.HF & Z.X")
Label(root, {'text': '人脸样本录入 - [SEU-PR]', 'font': '宋体 16'}).pack()
label_faceCount = Label(root, {'text': '当前人脸数:0', 'foreground': 'red'})
label_faceCount.pack()
display_area = Label(root, {'width': 100, 'height': 30, 'text': '请选择一种录入方式开始...'})
display_area.pack()
Button(root, {'text': '从摄像头录入', 'command': capture_camera}).pack({'side': LEFT})
Button(root, {'text': '从本地图片录入', 'command': ask_open_file}).pack({'side': LEFT})
Label(root, {'text': '请确保只有一张需要录入的人脸被框定!', 'foreground': 'red'}).pack({'side': LEFT})
Label(root, {'text': '请输入姓名:'}).pack({'side': LEFT})
input_label = Entry(root)
input_label.pack({'side': LEFT})
Button(root, {'text': '保存', 'command': save_sample}).pack({'side': LEFT})
root.mainloop()
camera.release()
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
Haar分类器结合keras-facenet算法实现人脸检测分割及人脸识别考勤系统完整源码+项目说明.zip 【模式识别-人脸识别考勤系统】 利用Haar分类器完成人脸检测、分割;利用FaceNet网络完成人脸识别。 【依赖库】 opencv-python numpy keras-facenet(见 https://pypi.org/project/keras-facenet/ ) Keras TensorFlow 其中,keras-facenet需要下载预训练模型置于~/.keras-facenet目录下,如果你获得的版本在model/目录下没有带该模型,请自行到该库的GitHub仓库页下载,或在第一次调用该库时也会自动下载。 【使用face_manager.py可以进行人脸的录入,注意录入姓名时,之间不要用空格分隔】 【使用main.py可以进行人脸考勤主操作】 准确率达到93.2% 【备注】主要针对正在做毕设的同学和需要项目实战的深度学习cv图像识别模式识别方向学习者。 也可作为课程设计、期末大作业。包含:项目源码、训练好的模型、项目操作说明等,该项目可直接作为毕设使用。
资源推荐
资源详情
资源评论
收起资源包目录
Haar分类器结合keras-facenet算法实现人脸检测分割及人脸识别考勤系统完整源码+项目说明(模式识别大作业).zip (25个子文件)
Haar分类器结合keras-facenet算法实现人脸检测分割及人脸识别考勤系统完整源码+项目说明(模式识别大作业)
main.py 3KB
model
haarcascade_frontalface_default.xml 1.2MB
test.py 1KB
dataset
manager.json 13B
__init__.py 0B
.idea
pca_face.iml 435B
misc.xml 189B
vcs.xml 180B
modules.xml 268B
workspace.xml 32KB
项目说明.md 2KB
FaceNet.py 2KB
legacy
PCA_test.py 2KB
ORB.py 832B
PCA_SVM.py 2KB
KNN.py 1KB
PCA_train.py 978B
image_refine.py 462B
LBPF_Fisher.py 877B
PCA.py 1KB
.gitignore 135B
face_manager.py 4KB
lib
keras_facenet-0.1a5-py3-none-any.whl 11KB
face_detection.py 1KB
face_demo_image.png 140KB
共 25 条
- 1
资源评论
Make程序设计
- 粉丝: 5725
- 资源: 3570
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 筷手引流工具.apk
- 论文(最终)_20240430235101.pdf
- 基于python编写的Keras深度学习框架开发,利用卷积神经网络CNN,快速识别图片并进行分类
- 最全空间计量实证方法(空间杜宾模型和检验以及结果解释文档).txt
- 5uonly.apk
- 蓝桥杯Python组的历年真题
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 前端开发技术实验报告:内含4四实验&实验报告
- Highlight Plus v20.0.1
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功