tjy/demo/ui/main_window.py

119 lines
4.4 KiB
Python
Raw Normal View History

2024-07-16 16:28:35 +08:00
import os
from PyQt5.QtWidgets import QMainWindow
from PyQt5.QtCore import pyqtSlot, QTimer, QDateTime
from PyQt5 import QtGui
from core.camera_thread import CameraThread
from core.storage_thread import StorageThread
from core.api_process import AIProcess
from core.update_thread import UpdateThread
from ui.ui import Ui_MainWindow
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.images_path = "images"
self.pic_dict = {
"Male": "male.png",
"Female": "female.png",
"ANGRY": "ANGRY.png",
"DISGUST": "DISGUST.png",
"FEAR": "FEAR.png",
"HAPPY": "HAPPY.png",
"NATURAL": "NATURAL.png",
"SAD": "SAD.png",
"SURPRISED": "SURPRISED.png",
"CONFUSED": "CONFUSED.png",
"SHY": "SHY.png",
}
for key in self.pic_dict.keys():
self.pic_dict[key] = os.path.join(self.images_path, self.pic_dict[key])
self.camera_thread = CameraThread()
self.storage_thread = StorageThread()
self.ai_process = AIProcess()
self.update_thread = UpdateThread(self.ai_process)
self.camera_thread.new_frame.connect(self.ui.update_image)
self.camera_thread.storage_frame.connect(self.storage_thread.store_frame)
self.camera_thread.fps_signal.connect(self.ai_process.update_fps)
self.storage_thread.frames_ready.connect(self.ai_process.process_frames)
self.ai_process.results_ready.connect(self.update_thread.update_ui)
self.update_thread.update_ui_signal.connect(self.update_ui)
self.camera_thread.start()
self.storage_thread.start()
self.ai_process.start()
self.update_thread.start()
# 设置定时器更新时间显示
self.timer = QTimer(self)
self.timer.timeout.connect(self.update_time)
self.timer.start(1000) # 每秒更新一次
@pyqtSlot(dict)
def update_ui(self, results):
# print(results)
# print("update ui")
Resp = results.get('resp', [])
if Resp is not None:
Resp[0] = self.ui.last_resp
for res in Resp:
self.ui.resps.put(res)
self.ui.last_resp = Resp[-1]
Bvp = results.get('bvp', [])
if Bvp is not None:
Bvp[0] = self.ui.last_bvp
for bvp in Bvp:
self.ui.bvps.put(bvp)
self.ui.last_bvp = Bvp[-1]
# 更新UI上的各项指标
self.ui.sbp_value.setText(str(results.get('sbp', '0')))
self.ui.dbp_value.setText(str(results.get('dbp', '0')))
self.ui.hr_value.setText(str(results.get('hr', '0')))
self.ui.cvrr_value.setText(str(results.get('cvrr', '0')))
self.ui.sdnn_value.setText(str(results.get('sdnn', '0')))
self.ui.rmssd_value.setText(str(results.get('rmssd', '0')))
self.ui.emotion_value.setText(results.get('emotion', '0'))
self.ui.rr_value.setText(str(results.get('rr', '0')))
self.ui.spo2_value.setText(str(results.get('spo2', '0')))
if results.get('skin_disease', '健康') != '健康':
self.ui.skin_diseance_value.setStyleSheet("background:rgb(13, 29, 66);\n"
"font-size:18pt;")
else:
self.ui.skin_diseance_value.setStyleSheet("background:rgb(13, 29, 66);\n"
"font-size:28pt;")
self.ui.skin_diseance_value.setText(results.get('skin_disease', '健康'))
self.ui.skin_ctype_value.setText(results.get('skin_type', '正常皮肤'))
self.ui.age_value.setProperty("value", results.get('age', 30))
self.ui.sex_value.setPixmap(QtGui.QPixmap(self.pic_dict.get(results.get('gender', 'Male'))))
self.ui.emotion_value.setText(results.get('emotion', 'NATURAL'))
self.ui.emotion_icon.setPixmap(QtGui.QPixmap(self.pic_dict.get(results.get('emotion', 'NATURAL'))))
def update_time(self):
current_time = QDateTime.currentDateTime()
time_display = current_time.toString('yyyy年MM月dd日 hh:mm:ss dddd')
self.ui.top.setText(time_display)
def closeEvent(self, event):
self.camera_thread.stop()
self.storage_thread.stop()
self.ai_process.stop()
self.update_thread.stop()
super().closeEvent(event)