基于人脸识别的课堂考勤系统

 

课堂考勤是保证学生出勤率的重要手段之一,也是学生课程成绩重要的组成部分,课堂考勤可以很好的监督学生,从而确保了课堂的教学质量。目前主要的考勤手段仍然是教师人工点名或者随机抽查的方式,这种人工点名的方式不仅占用上课时间而且无法解决学生的早退、代签和旷课等现象,无法很好的对学生考勤做到监管.市面上也存在着各种各样的考勤机,但是由于硬件和部署的成本较高,无法很好的解决考勤问题。

为了解决上述的问题,本文采用人脸识别技术,设计实现了一个适合日常课堂考勤的自动化人脸识别考勤系统,主要研究了该系统的设计与功能的实现。阐述了人脸识别技术的基本概念、发展阶段和基本方法,分析了传统考勤方式的不足,同时也介绍了国内外相关技术的发展历史和研究成果。接着详细介绍了活体检测、人脸检测及人脸识别的主要方法。然后根据考勤系统在功能和性能上的各种需求,进行软件架构的设计。最终整体介绍系统的功能以及测试内容,并展示了相应的GUI界面。

利用python实现人脸识别技术是基于mtcnn和facenet考勤

实现了人脸大角度识别

import cv2
import os
import numpy as np
from net.mtcnn import mtcnn
import utils.utils as utils
from net.inception import InceptionResNetV1
import time
from dateutil.parser import parsefont = cv2.FONT_HERSHEY_COMPLEXdef seekopp(list_2,i):for j in range(i-1,-1,-1):if list_2[j]==0:continue elif list_2[j]>0:return 1elif list_2[j]<0:return 0def local_maximum(list_1):a=len(list_1)if a==0:return 'error'if a==1:return list_1if a==2:if list_1[0]>list_1[1]:return list_1[0]elif list_1[0]<list_1[1]:return list_1[1]else:return list_1if a>2:list_2=[]index_1=[]for i in range(0,a-1):list_2.append(list_1[i+1]-list_1[i])b=len(list_2)if list_2[0]<0:index_1.append(0)for i in range(0,b-1):if list_2[i+1]<0:if list_2[i]>0:index_1.append(i+1)elif list_2[i]==0:if seekopp(list_2,i):index_1.append(i+1)else:continue else:continue list_3=[]for i in index_1:list_3.append(list_1[i])return list_3def transform(t1,t2):timeArray1 = time.localtime(t1)timeArray2 = time.localtime(t2)time_1 = time.strftime("%Y-%m-%d %H:%M:%S", timeArray1)time_2 = time.strftime("%Y-%m-%d %H:%M:%S", timeArray2)date1 = parse(time_1)date2 = parse(time_2)result = int((date2 - date1).total_seconds())return resultclass face_rec():time = 0def __init__(self):# 创建mtcnn对象# 检测图片中的人脸self.mtcnn_model = mtcnn()# 门限函数self.threshold = [0.5,0.8,0.9]# 载入facenet# 将检测到的人脸转化为128维的向量self.facenet_model = InceptionResNetV1()# model.summary()model_path = './model_data/facenet_keras.h5'self.facenet_model.load_weights(model_path)#-----------------------------------------------##   对数据库中的人脸进行编码#   known_face_encodings中存储的是编码后的人脸#   known_face_names为人脸的名字#-----------------------------------------------#face_list = os.listdir("face_dataset")self.known_face_encodings=[]self.known_face_names=[]self.time_list=[]self_learn_time = 0self.total_time = []for face in face_list:name = face.split(".")[0]img = cv2.imread("./face_dataset/"+face)img = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)# 检测人脸rectangles = self.mtcnn_model.detectFace(img, self.threshold)# 转化成正方形rectangles = utils.rect2square(np.array(rectangles))# facenet要传入一个160x160的图片rectangle = rectangles[0]# 记下他们的landmarklandmark = (np.reshape(rectangle[5:15],(5,2)) - np.array([int(rectangle[0]),int(rectangle[1])]))/(rectangle[3]-rectangle[1])*160crop_img = img[int(rectangle[1]):int(rectangle[3]), int(rectangle[0]):int(rectangle[2])]crop_img = cv2.resize(crop_img,(160,160))new_img,_ = utils.Alignment_1(crop_img,landmark)new_img = np.expand_dims(new_img,0)# 将检测到的人脸传入到facenet的模型中,实现128维特征向量的提取face_encoding = utils.calc_128_vec(self.facenet_model,new_img)self.known_face_encodings.append(face_encoding)self.known_face_names.append(name)def recognize(self,draw):#-----------------------------------------------##   人脸识别#   先定位,再进行数据库匹配#-----------------------------------------------#height,width,_ = np.shape(draw)draw_rgb = cv2.cvtColor(draw,cv2.COLOR_BGR2RGB)# 检测人脸rectangles = self.mtcnn_model.detectFace(draw_rgb, self.threshold)'''if len(rectangles)==0:font = cv2.FONT_HERSHEY_SIMPLEXif time_flag==0:print('首次执行!')first_time = time.time()t = transform(int(first_time),int(time.time()))cv2.putText(draw, "Focus on time:"+str(t)+" s", (250, 40), font, 0.6, (0, 255, 0), 1, cv2.LINE_AA)time_flag==1returnelse:print('第二次执行!')t = transform(int(first_time),int(time.time()))cv2.putText(draw, "Focus on time:"+str(t)+" s", (250, 40), font, 0.6, (0, 255, 0), 1, cv2.LINE_AA)return'''if len(rectangles)==0:self.time_list.append(time.time())font = cv2.FONT_HERSHEY_SIMPLEXt = transform(self.time_list[0],self.time_list[-1])#print(t,type(t))cv2.putText(draw, "Noface", (40, 40), font, 0.6, (0, 255, 0), 1, cv2.LINE_AA)cv2.putText(draw, "Focus on time:"+str(t)+" s", (350, 40), font, 0.6, (0, 255, 0), 1, cv2.LINE_AA)#print(self.total_time,type(self.total_time))if len(self.total_time)==0:self.total_time.append(t)elif self.total_time[-1]<= t:self.total_time.pop()self.total_time.append(t)elif self.total_time[-1]>= t:self.total_time.append(t)else:passreturn draw,self.total_timeself.time_list.clear()# 转化成正方形rectangles = utils.rect2square(np.array(rectangles,dtype=np.int32))rectangles[:,0] = np.clip(rectangles[:,0],0,width)rectangles[:,1] = np.clip(rectangles[:,1],0,height)rectangles[:,2] = np.clip(rectangles[:,2],0,width)rectangles[:,3] = np.clip(rectangles[:,3],0,height)#-----------------------------------------------##   对检测到的人脸进行编码#-----------------------------------------------#face_encodings = []for rectangle in rectangles:landmark = (np.reshape(rectangle[5:15],(5,2)) - np.array([int(rectangle[0]),int(rectangle[1])]))/(rectangle[3]-rectangle[1])*160crop_img = draw_rgb[int(rectangle[1]):int(rectangle[3]), int(rectangle[0]):int(rectangle[2])]crop_img = cv2.resize(crop_img,(160,160))new_img,_ = utils.Alignment_1(crop_img,landmark)new_img = np.expand_dims(new_img,0)face_encoding = utils.calc_128_vec(self.facenet_model,new_img)face_encodings.append(face_encoding)face_names = []for face_encoding in face_encodings:# 取出一张脸并与数据库中所有的人脸进行对比,计算得分matches = utils.compare_faces(self.known_face_encodings, face_encoding, tolerance = 0.9)name = "Unknown"# 找出距离最近的人脸face_distances = utils.face_distance(self.known_face_encodings, face_encoding)# 取出这个最近人脸的评分best_match_index = np.argmin(face_distances)if matches[best_match_index]:name = self.known_face_names[best_match_index]face_names.append(name)rectangles = rectangles[:,0:4]#-----------------------------------------------##   画框~!~#-----------------------------------------------#for (left, top, right, bottom), name in zip(rectangles, face_names):cv2.rectangle(draw, (left, top), (right, bottom), (0, 0, 255), 2)font = cv2.FONT_HERSHEY_SIMPLEXcv2.putText(draw, name, (left , bottom - 15), font, 0.75, (255, 255, 255), 2) if name!='Unknown':cv2.putText(draw, 'name:'+name, (10, 20), font, 0.6, (0, 255, 0), 1, cv2.LINE_AA)cv2.putText(draw, "state:"+"clock on", (10, 60), font, 0.6, (0, 255, 0), 1, cv2.LINE_AA)cv2.putText(draw, "Please concentrate on your study!", (200, 40), font, 0.6, (0, 0, 255), 1, cv2.LINE_AA)else:cv2.putText(draw, 'name:'+name, (10, 20), font, 0.6, (0, 255, 0), 1, cv2.LINE_AA)cv2.putText(draw, "state:"+"clock out failed", (10, 60), font, 0.6, (0, 255, 0), 1, cv2.LINE_AA)cv2.putText(draw, "Please add face!", (300, 40), font, 0.6, (0, 0, 255), 1, cv2.LINE_AA)return draw,self.total_timeif __name__ == "__main__":dududu = face_rec()video_capture = cv2.VideoCapture(0)while True:ret, draw = video_capture.read()dududu.recognize(draw) cv2.imshow('Video', draw)if cv2.waitKey(20) & 0xFF == ord('q'):breakvideo_capture.release()cv2.destroyAllWindows()

python人脸识别基于mtcnn和facenet考勤相关推荐

  1. mtcnn人脸检测python_基于mtcnn和facenet的实时人脸检测与识别系统开发

    简介:本文主要介绍了实时人脸检测与识别系统的详细方法.该系统基于python/opencv2/tensorflow环境,实现了从摄像头读取视频,检测人脸,识别人脸的功能.本系统代码地址:real ti ...

  2. 基于MTCNN和FaceNet的实时人脸检测识别系统

    文章目录 模型介绍 MTCNN FaceNet 基于MTCNN和FaceNet的实时人脸检测识别系统 在LFW数据集上测试 参考文献 GitHub项目地址:https://github.com/Har ...

  3. python人脸识别考勤系统 dlib+OpenCV和Pyqt5、数据库sqlite 人脸识别系统 计算机 毕业设计 源码

    一.项目介绍 Python语言.dlib.OpenCV.Pyqt5界面设计.sqlite3数据库 本系统使用dlib作为人脸识别工具,dlib提供一个方法可将人脸图片数据映射到128维度的空间向量,如 ...

  4. 【优秀课设】基于OpenCV的Python人脸识别、检测、框选(遍历目录下所有照片依次识别 视频随时标注)

    基于OpenCV的Python人脸识别.检测.框选 (遍历目录下所有照片依次识别 视频随时标注) 移步: https://blog.csdn.net/weixin_53403301/article/d ...

  5. Python人脸识别教程 - 基于Python的开源人脸识别库:离线识别率高达99.38%

    Python人脸识别教程 - 基于Python的开源人脸识别库:离线识别率高达99.38% 仅用 Python 和命令行就可以实现人脸识别的库开源了.该库使用 dlib 顶尖的深度学习人脸识别技术构建 ...

  6. 视觉识别入门之人脸识别——基于FACENET的高精度人脸识别

    视觉识别入门之人脸识别---- 基于FACENET的高精度人脸识别 一:项目展示: - 这是实时视频读取的展示,是可以读单张图片,或者本地视频流,抑或是实时人脸检测与分类的,至于我为什么不展示我的自拍 ...

  7. matlab人脸识别样本库建立,facenet 人脸识别(二)——创建人脸库搭建人脸识别系统...

    搭建人脸库 选择的方式是从百度下载明星照片 照片下载,downloadImageByBaidu.py # coding=utf-8 """ 爬取百度图片的高清原图 &qu ...

  8. Python人脸识别——从入门到工程实践

    参考书籍:<Python人脸识别从入门到工程实践> 全书共8章: 第 1 章:介绍了人脸识别的基础知识和必备常识: 第 2~4 章:详细讲解了与人脸识别相关的数学.机器学习.计算机视觉.O ...

  9. Python | 人脸识别系统(人脸识别、活体检测、背景模糊、关键点检测)

    本博客为人脸识别系统项目简介 项目GitHub完整源代码地址:Su-Face-Recognition: A face recognition for user logining 一.运行环境 本系统能 ...

最新文章

  1. 火热的激情、严密的计划成就双冠梦想——我的项管经验(转载)
  2. 模拟post请求--测试api是否可用--再交给ios开发
  3. 查看go 安装了哪些包_如何灵活地进行 Go 版本管理
  4. ubuntu创建wifi热点plasma-nm
  5. man-翻译和epoll相关的内容,部分
  6. oracle is null效率,Oracle查询优化之is null和is not null优化
  7. 分类算法——决策树算法及其R实现
  8. 过Serverless技术降低微服务应用资源成本
  9. 闹猴网页特效集软件 v1.0.5.21
  10. Bootstrap 弹出提示插件Popover 的选项
  11. python 运算符重载_《fluent python》第 13 章 正确重载运算符
  12. 克鲁赛德战记服务器无响应,克鲁赛德战记闪退黑屏登不上怎么办 解决方法
  13. uva 10098 Generating Fast
  14. JRebel-JVMTI [FATAL] Couldn‘t write to C:\Users\【完美解决方案】
  15. IDEA添加gitlab仓库并上传代码(无需使用任何git指令),报错Ask a project Owner or Maintainer to create a default branch解决方案
  16. 用python编程点菜系统_python3实现点餐系统
  17. 【面试时最令职场面试官讨厌的十种行为】
  18. Googlenbsp;Calendarnbsp;与amp;nbs…
  19. 【深入UCSC Genome Brower】他山之石
  20. 逻辑英语结构【重点】

热门文章

  1. mysql 整理碎片_mysql 如何去整理表数据,碎片整理
  2. Linux防火墙查看及白名单添加
  3. 销售新冠检测试剂需要办理什么证件?
  4. fatal: adding files failed
  5. 单口RAM、伪双口RAM、双口RAM与FIFO的区别
  6. 00后php团队,00后视频创作团队变身能力担当
  7. 问题 G: 深入浅出学算法007-求佩尔方程的解
  8. 分享|中国制造业数字化转型研究报告(附PDF)
  9. My love, you are always in my heart
  10. PDF监制章的java实现方式