1.人脸验证执行操作成功

2.UI底图进行修改
This commit is contained in:
冯佳
2025-09-13 11:08:46 +08:00
parent a3bb7f0701
commit 621c107be1
23 changed files with 247 additions and 245 deletions

View File

@ -801,37 +801,125 @@ class UIFrameWork(QMainWindow, class_comm_mqtt_interface):
print("密码认证成功")
elif choice == "face":
# face_page = self.parent_window.P05_01_FaceCameraView
input = True
# 人脸认证异步处理
face_frame = self.parent_window.P05_01_FaceCameraView
face_frame.face_verify_result = None # 重置标志位
self.do_verify() # 发送 CMD_VERIFY
timeout = system_parameter().get_verify_timeout()
start_time = time.time()
# 创建定时器轮询标志位
self._face_verify_timer = QTimer(self)
self._face_verify_timer.setInterval(50) # 每50ms检查一次
def check_face_result():
nonlocal input
if face_frame.face_verify_result is not None:
self._face_verify_timer.stop()
if face_frame.face_verify_result:
input = True
inform_box = DialogInform()
inform_box.information("提示", "人脸认证成功")
self._after_face_verify(select_object, action_str)
else:
input = False
inform_box = DialogInform()
inform_box.information("提示", "人脸认证失败")
elif time.time() - start_time > timeout:
self._face_verify_timer.stop()
input = False
inform_box = DialogInform()
inform_box.information("提示", "人脸认证超时")
self._face_verify_timer.timeout.connect(check_face_result)
self._face_verify_timer.start()
return # 异步处理,直接返回
else:
# 无认证要求,直接通过
input = True
if input :
if "CmdExecute" in action_str :
mqtt_name = get_tip_mqtt_name(tip_str)
unique_name = self.get_unique_name_from_object(select_object)
if mqtt_name != None and unique_name != None:
if len(mqtt_name) > 0 and self.mqtt_thread != None:
publish_topic = "request/action/" + unique_name
publish_message = '{"name" : "%s"}'%(mqtt_name)
self.mqtt_publish_and_wait_response(publish_topic, publish_message, select_object, 1000)
elif "ModifySystem" in action_str:
self.on_system_param_modify(tip_str)
elif "Modify" in action_str :
if isinstance(select_object, QLineEdit) :
self.on_line_edit_modify_click(select_object)
elif "Users" in action_str :
self.do_manage_users()
elif "Verify" in action_str :
self.do_verify()
elif "EnrollItgSingle" in action_str :
self.do_enroll_itg_single()
elif "Reset" in action_str :
self.reset_command()
self.virtual_widget_action_process(select_object, action_str)
# ---------------- 认证成功后执行操作 ----------------
if input:
if "CmdExecute" in action_str:
mqtt_name = get_tip_mqtt_name(tip_str)
unique_name = self.get_unique_name_from_object(select_object)
if mqtt_name and unique_name and self.mqtt_thread and len(mqtt_name) > 0:
publish_topic = "request/action/" + unique_name
publish_message = '{"name" : "%s"}' % mqtt_name
self.mqtt_publish_and_wait_response(publish_topic, publish_message, select_object, 1000)
elif "ModifySystem" in action_str:
self.on_system_param_modify(tip_str)
elif "Modify" in action_str and isinstance(select_object, QLineEdit):
self.on_line_edit_modify_click(select_object)
elif "Users" in action_str:
self.do_manage_users()
elif "Verify" in action_str:
self.do_verify()
elif "EnrollItgSingle" in action_str:
self.do_enroll_itg_single()
elif "Reset" in action_str:
self.reset_command()
elif "ConnectCamera" in action_str:
self.connectcamera()
elif "VideoMode" in action_str:
self.toggle_video_mode()
elif "FaceBox" in action_str:
self.toggle_face_box()
self.virtual_widget_action_process(select_object, action_str)
# ------------------ 后续操作回调 ------------------
def _after_face_verify(self, select_object, action_str):
"""
人脸认证成功后调用,继续执行后续动作
"""
if "CmdExecute" in action_str:
mqtt_name = get_tip_mqtt_name(select_object.statusTip())
unique_name = self.get_unique_name_from_object(select_object)
if mqtt_name and unique_name and self.mqtt_thread and len(mqtt_name) > 0:
publish_topic = "request/action/" + unique_name
publish_message = '{"name" : "%s"}' % mqtt_name
self.mqtt_publish_and_wait_response(publish_topic, publish_message, select_object, 1000)
elif "ModifySystem" in action_str:
self.on_system_param_modify(select_object.statusTip())
elif "Modify" in action_str and isinstance(select_object, QLineEdit):
self.on_line_edit_modify_click(select_object)
elif "Users" in action_str:
self.do_manage_users()
elif "Verify" in action_str:
self.do_verify()
elif "EnrollItgSingle" in action_str:
self.do_enroll_itg_single()
elif "Reset" in action_str:
self.reset_command()
elif "ConnectCamera" in action_str:
self.connectcamera()
elif "VideoMode" in action_str:
self.toggle_video_mode()
elif "FaceBox" in action_str:
self.toggle_face_box()
self.virtual_widget_action_process(select_object, action_str)
def search_menu_match_object(self, object) :
match_object : QWidget = None
@ -850,6 +938,7 @@ class UIFrameWork(QMainWindow, class_comm_mqtt_interface):
timeout_val = system_parameter().get_verify_timeout()
self.send(build_verify(pd_val, timeout_val))
def do_enroll_itg_single(self):
dlg = EnrollItgSingleDialog(self)
if dlg.exec_() == QDialog.Accepted:
@ -862,6 +951,74 @@ class UIFrameWork(QMainWindow, class_comm_mqtt_interface):
def reset_command(self):
self.send(build_reset())
def connectcamera(self):
running = self.video_worker and self.video_worker.isRunning()
if running:
self.video_worker.stop()
self.video_worker.wait(300)
self.video_worker = None
self.video_label.setText("未打开")
self.video_label.setPixmap(QPixmap())
self.btn_video.setText("打开视频")
self.log("[INFO] 视频已关闭")
inform_box : DialogInform = DialogInform()
inform_box.information("提示", "视频已关闭")
return
if self.video_label.width()<50 or self.video_label.height()<50:
self.video_label.setMinimumSize(360,480)
self.video_worker = VideoWorker(cam_index=0, target_size=self.video_label.size())
self.video_worker.pixmap_ready.connect(self.video_label.setPixmap)
self.video_worker.log_message.connect(self.log)
self.video_worker.start()
self.btn_video.setText("关闭视频")
self.log("[INFO] 正在打开视频")
inform_box : DialogInform = DialogInform()
inform_box.information("提示", "正在打开视频")
def toggle_video_mode(self):
if self.current_video_mode==0:
self.send_uvc(1)
self.current_video_mode=1
self.log("[INFO] 已切换到红外视频模式")
inform_box : DialogInform = DialogInform()
inform_box.information("提示", "已切换到红外视频模式")
else:
self.send_uvc(0)
self.current_video_mode=0
self.log("[INFO] 已切换到彩色视频模式")
inform_box : DialogInform = DialogInform()
inform_box.information("提示", "已切换到彩色视频模式")
def toggle_face_box(self):
if self.current_face_box==0:
self.send_face_box(1)
self.current_face_box=1
self.log("[INFO] 人脸框已开启")
inform_box : DialogInform = DialogInform()
inform_box.information("提示", "人脸框已开启")
else:
self.send_face_box(0)
self.current_face_box=0
self.log("[INFO] 人脸框已关闭")
inform_box : DialogInform = DialogInform()
inform_box.information("提示", "人脸框已关闭")
# ---------------- 发送指令 ----------------
def send_uvc(self, mode):
if self.ser and getattr(self.ser,"is_open",False):
self.ser.write(build_uvc_view(mode))
else:
self.log("[WARN] 串口未连接,无法切换视频模式")
def send_face_box(self, state):
if self.ser and getattr(self.ser,"is_open",False):
self.ser.write(build_face_view(state))
else:
self.log("[WARN] 串口未连接,无法控制人脸框")
################################################################################
#刷新屏幕上的系统信息, 例如时间日期之类
@ -1009,10 +1166,8 @@ class UIFrameWork(QMainWindow, class_comm_mqtt_interface):
modify_screen_time_str = dialog_modify_text.value
result = frt.set_verify_timeout(modify_screen_time_str)
if result is not None:
self.FaceRecogTimeoutEdit.setText(str(result))
dialog_inform = DialogInform(self)
dialog_inform.information("人脸识别超时时间修改", "人脸识别超时时间修改成功")
dialog_inform = DialogInform(self)
dialog_inform.information("人脸识别超时时间修改", "人脸识别超时时间修改成功")
def on_line_edit_modify_click(self, sender :QLineEdit) :
match_object : QLineEdit = None