基于人脸识别的门禁系统设计与实现--论文

  • 2
    点赞
  • 33
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
好的,下面是一个基于人脸识别门禁系统设计实现,并附上代码以及数据库: 1. 硬件设备:需要使用一台摄像头和一台门禁控制器。 2. 软件环境:需要安装OpenCV、Python、Dlib等相关软件。 3. 数据库设计:需要设计一个数据库存储人员信息,包括姓名、照片、权限等信息。 以下是数据库的设计: ``` CREATE TABLE `employee` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(50) NOT NULL, `photo` varchar(255) NOT NULL, `permission` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; ``` 4. 代码实现:我们需要实现以下功能: - 采集人脸信息:使用摄像头采集人脸信息,存储到数据库中。 - 人脸识别:使用OpenCV和Dlib进行人脸检测和人脸识别,判断是否为已知人员。 - 权限控制:根据人员权限和当前时间,判断是否可以进入。 - 记录日志:记录每个人员的进出时间和门禁状态。 以下是Python代码实现: ```python import cv2 import dlib import numpy as np import pymysql import time # 连接数据库 conn = pymysql.connect(host='localhost', port=3306, user='root', password='123456', db='face_recognition') cursor = conn.cursor() # 加载人脸检测器和识别器 detector = dlib.get_frontal_face_detector() predictor = dlib.shape_predictor('shape_predictor_68_face_landmarks.dat') facerec = dlib.face_recognition_model_v1('dlib_face_recognition_resnet_model_v1.dat') # 读取数据库中的人脸信息 cursor.execute('SELECT * FROM employee') rows = cursor.fetchall() known_face_encodings = [] known_face_names = [] for row in rows: name = row[1] photo_path = row[2] permission = row[3] # 读取人脸照片,并进行编码 img = cv2.imread(photo_path) face_locations = detector(img, 1) face_encodings = facerec.compute_face_descriptor(img, face_locations[0]) known_face_encodings.append(face_encodings) known_face_names.append(name) # 打开摄像头 cap = cv2.VideoCapture(0) # 循环处理每一帧图像 while True: ret, img = cap.read() if ret == False: break # 人脸检测 face_locations = detector(img, 1) if len(face_locations) > 0: # 人脸识别 face_encodings = facerec.compute_face_descriptor(img, face_locations[0]) face_distances = np.linalg.norm(known_face_encodings - face_encodings, axis=1) min_index = np.argmin(face_distances) if face_distances[min_index] < 0.6: name = known_face_names[min_index] permission = rows[min_index][3] # 权限控制 if permission == 0: access = False else: current_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()) if permission == 1 or permission == 2: access = True else: cursor.execute('SELECT * FROM access_log WHERE name=%s AND access_time>%s', [name, current_time]) rows = cursor.fetchall() if len(rows) > 0: access = False else: access = True # 记录日志 cursor.execute('INSERT INTO access_log(name, access_time, access) VALUES(%s, %s, %s)', [name, current_time, access]) conn.commit() # 显示人员姓名和门禁状态 cv2.putText(img, name, (face_locations[0].left, face_locations[0].top - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.75, (0, 0, 255), 2) if access: cv2.putText(img, 'Access Allowed', (face_locations[0].left, face_locations[0].bottom + 20), cv2.FONT_HERSHEY_SIMPLEX, 0.75, (0, 255, 0), 2) else: cv2.putText(img, 'Access Denied', (face_locations[0].left, face_locations[0].bottom + 20), cv2.FONT_HERSHEY_SIMPLEX, 0.75, (0, 0, 255), 2) # 显示图像 cv2.imshow('Face Recognition', img) if cv2.waitKey(1) & 0xFF == ord('q'): break # 关闭摄像头和数据库连接 cap.release() cv2.destroyAllWindows() cursor.close() conn.close() ``` 以上是一个基于人脸识别门禁系统设计实现,具体实现可以根据实际需求进行调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

凌晨里的无聊人

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值