更改部分bug加入人脸识别锁机制
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
import sys
|
||||
import os
|
||||
import time
|
||||
import csv
|
||||
import inspect
|
||||
import cv2
|
||||
import json
|
||||
@ -10,7 +11,7 @@ from PyQt5 import uic
|
||||
from PyQt5.QtGui import QImage, QPixmap, QColor,QBrush, QKeySequence, QIcon, QPalette
|
||||
from PyQt5.QtCore import Qt, QThread, pyqtSignal, QObject, QRunnable, QMutex, QTimer, QEvent, QSize, QDateTime
|
||||
from PyQt5.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QFrame, QWidget, QLayout, QLabel
|
||||
from PyQt5.QtWidgets import QLineEdit, QPushButton, QMessageBox, QShortcut, QDialog
|
||||
from PyQt5.QtWidgets import QLineEdit, QPushButton, QMessageBox, QShortcut, QDialog,QTableWidgetItem
|
||||
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
||||
from Shared_CODE.CameraThread import CameraThread
|
||||
import menu_utils as utils
|
||||
@ -22,7 +23,7 @@ from Shared_CODE.DialogModifyText import DialogModifyText
|
||||
from Shared_CODE.DialogInform import DialogInform
|
||||
from QT5_Project.Shared_CODE.FaceRecognitionProtocol import parse_reply
|
||||
from QT5_Project.Shared_CODE.DialogFaceEnrollItgSingle import EnrollItgSingleDialog
|
||||
from QT5_Project.Shared_CODE.DialogFaceUserManage import UserManageDialog
|
||||
from QT5_Project.Shared_CODE.DialogFaceUserManage import UserManageDialog, load_users, save_user, save_users_list, CSV_FILE
|
||||
|
||||
from Shared_CODE.get_tip_prop import *
|
||||
from print_color import *
|
||||
@ -801,6 +802,8 @@ class UIFrameWork(QMainWindow, class_comm_mqtt_interface):
|
||||
print("密码认证成功")
|
||||
|
||||
elif choice == "face":
|
||||
# 初始化锁标志
|
||||
self._face_verify_locked = True # 开始验证时锁定
|
||||
# 人脸认证异步处理
|
||||
face_frame = self.parent_window.P05_01_FaceCameraView
|
||||
face_frame.face_verify_result = None # 重置标志位
|
||||
@ -809,6 +812,12 @@ class UIFrameWork(QMainWindow, class_comm_mqtt_interface):
|
||||
timeout = system_parameter().get_verify_timeout()
|
||||
start_time = time.time()
|
||||
|
||||
# 停止并删除旧定时器
|
||||
if hasattr(self, "_face_verify_timer"):
|
||||
if self._face_verify_timer.isActive():
|
||||
self._face_verify_timer.stop()
|
||||
self._face_verify_timer.deleteLater()
|
||||
|
||||
# 创建定时器轮询标志位
|
||||
self._face_verify_timer = QTimer(self)
|
||||
self._face_verify_timer.setInterval(50) # 每50ms检查一次
|
||||
@ -817,6 +826,7 @@ class UIFrameWork(QMainWindow, class_comm_mqtt_interface):
|
||||
nonlocal input
|
||||
if face_frame.face_verify_result is not None:
|
||||
self._face_verify_timer.stop()
|
||||
self._face_verify_locked = False # 解锁
|
||||
if face_frame.face_verify_result:
|
||||
input = True
|
||||
inform_box = DialogInform()
|
||||
@ -828,10 +838,15 @@ class UIFrameWork(QMainWindow, class_comm_mqtt_interface):
|
||||
inform_box.information("提示", "人脸认证失败")
|
||||
elif time.time() - start_time > timeout:
|
||||
self._face_verify_timer.stop()
|
||||
self._face_verify_locked = False # 解锁
|
||||
input = False
|
||||
inform_box = DialogInform()
|
||||
inform_box.information("提示", "人脸认证超时")
|
||||
|
||||
# 解绑旧槽,绑定新槽
|
||||
try:
|
||||
self._face_verify_timer.timeout.disconnect()
|
||||
except Exception:
|
||||
pass
|
||||
self._face_verify_timer.timeout.connect(check_face_result)
|
||||
self._face_verify_timer.start()
|
||||
return # 异步处理,直接返回
|
||||
@ -875,6 +890,11 @@ class UIFrameWork(QMainWindow, class_comm_mqtt_interface):
|
||||
|
||||
elif "FaceBox" in action_str:
|
||||
self.toggle_face_box()
|
||||
|
||||
elif "DeleteUser" in action_str:
|
||||
self.delete_user_by_id()
|
||||
elif "UserCount" in action_str:
|
||||
self.query_user_count()
|
||||
|
||||
self.virtual_widget_action_process(select_object, action_str)
|
||||
|
||||
@ -919,6 +939,12 @@ class UIFrameWork(QMainWindow, class_comm_mqtt_interface):
|
||||
elif "FaceBox" in action_str:
|
||||
self.toggle_face_box()
|
||||
|
||||
elif "DeleteUser" in action_str:
|
||||
self.delete_user_by_id()
|
||||
|
||||
elif "UserCount" in action_str:
|
||||
self.query_user_count()
|
||||
|
||||
self.virtual_widget_action_process(select_object, action_str)
|
||||
|
||||
def search_menu_match_object(self, object) :
|
||||
@ -936,7 +962,8 @@ class UIFrameWork(QMainWindow, class_comm_mqtt_interface):
|
||||
def do_verify(self):
|
||||
pd_val = 0
|
||||
timeout_val = system_parameter().get_verify_timeout()
|
||||
self.send(build_verify(pd_val, timeout_val))
|
||||
face_send = self.parent_window.P05_01_FaceCameraView
|
||||
face_send.send(build_verify(pd_val, timeout_val))
|
||||
|
||||
|
||||
def do_enroll_itg_single(self):
|
||||
@ -1019,6 +1046,69 @@ class UIFrameWork(QMainWindow, class_comm_mqtt_interface):
|
||||
else:
|
||||
self.log("[WARN] 串口未连接,无法控制人脸框")
|
||||
|
||||
def delete_user_by_id(self, CSV_FILE = CSV_FILE):
|
||||
users = load_users()
|
||||
|
||||
# 弹出对话框选择用户ID
|
||||
dialog_modify_text = DialogModifyValue(self)
|
||||
caption_str = "选择用户ID删除"
|
||||
dialog_modify_text.update_modify_info("", 0, caption_str)
|
||||
|
||||
if dialog_modify_text.exec() != QDialog.Accepted:
|
||||
return
|
||||
|
||||
# 获取用户输入的ID并转换为整数
|
||||
try:
|
||||
user_id = int(dialog_modify_text.value)
|
||||
except ValueError:
|
||||
DialogInform(self).information("提示", "请输入有效数字ID")
|
||||
return
|
||||
|
||||
# 查找用户
|
||||
user = next((u for u in users if u["user_id"] == user_id), None)
|
||||
if not user:
|
||||
DialogInform(self).information("提示", "用户不存在")
|
||||
return
|
||||
|
||||
try:
|
||||
# 1️⃣ 下发删除命令
|
||||
self.send(build_delete_user(user_id))
|
||||
|
||||
# 2️⃣ 删除 CSV 文件对应行
|
||||
if os.path.exists(CSV_FILE):
|
||||
with open(CSV_FILE, "r", encoding="utf-8", newline="") as f:
|
||||
reader = csv.DictReader(f)
|
||||
fieldnames = reader.fieldnames
|
||||
new_rows = [row for row in reader if str(row.get("user_id")) != str(user_id)]
|
||||
|
||||
with open(CSV_FILE, "w", encoding="utf-8", newline="") as f:
|
||||
writer = csv.DictWriter(f, fieldnames=fieldnames)
|
||||
writer.writeheader()
|
||||
writer.writerows(new_rows)
|
||||
|
||||
except Exception as e:
|
||||
DialogInform(self).information("提示", f"删除失败: {e}")
|
||||
return
|
||||
|
||||
# 3️⃣ 更新内存用户列表
|
||||
users = [u for u in users if u["user_id"] != user_id]
|
||||
save_users_list(users)
|
||||
|
||||
# 4️⃣ 提示删除成功
|
||||
DialogInform(self).information("提示", f"用户 {user.get('user_name', '')} (ID={user_id}) 已删除")
|
||||
|
||||
|
||||
def query_user_count(self):
|
||||
self.send(build_get_all_userid())
|
||||
|
||||
def refresh(self):
|
||||
users = load_users()
|
||||
self.table.setRowCount(len(users))
|
||||
for r, u in enumerate(users):
|
||||
self.table.setItem(r, 0, QTableWidgetItem(str(u.get("user_id", ""))))
|
||||
self.table.setItem(r, 1, QTableWidgetItem(u.get("user_name", "")))
|
||||
self.table.setItem(r, 2, QTableWidgetItem(u.get("created_at", "")))
|
||||
|
||||
|
||||
################################################################################
|
||||
#刷新屏幕上的系统信息, 例如时间日期之类
|
||||
|
||||
Reference in New Issue
Block a user