简单的人脸识别签到程序
这是我自己根据之前的文章《简单的签到程序》修改出来签到程序,还在学习之中,代码还有很多可以优化的地方。
UI代码
有不少地方可以优化一下,但是不想改了。
import PySimpleGUI as sg
from MYSQL1 import *
import cv2
import face_recognition
import os
import numpy as np
#文件路径
file_path = "D:\work\python\open\lian"
def UI():
c = cv2.VideoCapture(0, cv2.CAP_DSHOW)# 打开摄像头
if c.isOpened() == False:
print("没有开启摄像头")
return
# 创建一个简单的窗口,包含一个标签和一个输入框
Layout = [[sg.Text("编号: ", size=(10, 1)), sg.InputText(key='id')],
[sg.Text("姓名: ", size=(10, 1)), sg.InputText(key='name')],
[sg.Text(key='msg')],
[sg.Button("采集"), sg.Button('签到'),sg.Button('查询'), sg.Button("关闭")],
[sg.Image(key="video", size=(640, 380))]]
window = sg.Window("人脸识别", Layout, finalize=True)
while True:
event, values = window.read(timeout=100) # 读取窗口事件和输入值
ret,frame = c.read()
id = values["id"]
name = values["name"]
if ret == True:
imgType = cv2.imencode('.png', frame)[1].tobytes()
# print(imgType)
window['video'].update(data=imgType)
if event == "采集":
if id and name:
window["msg"].update(f"编号: {
id}, 姓名: {
name}") # 更新消息框内容
face_list = face_recognition.face_locations(frame)
if num_to_all(id)