def button_open_camera_click(self): if self.timer_camera.isActive() == False: # 检查定时状态 flag = self.cap.open(self.CAM_NUM) # 检查相机状态 if flag == False: # 相机打开失败提示 msg = QtWidgets.QMessageBox.warning( self.centralwidget, u"Warning", u"请检测相机与电脑是否连接正确! ", buttons=QtWidgets.QMessageBox.Ok, defaultButton=QtWidgets.QMessageBox.Ok) else: # 准备运行识别程序 QtWidgets.QApplication.processEvents() self.label_face.setText('正在启动识别系统...\n\nleading') # 新建对象 self.emotion_model = Emotion_Rec(self.model_path) QtWidgets.QApplication.processEvents() # 打开定时器 self.timer_camera.start(30) else: # 定时器未开启,界面回复初始状态 self.timer_camera.stop() self.cap.release() self.label_face.clear() gif = QMovie(':/newPrefix/images_test/scan.gif') self.label_face.setMovie(gif) gif.start() self.label_outputResult.clear() self.label_outputResult.setStyleSheet( "border-image: url(:/newPrefix/images_test/ini.png);") self.label_scanResult.setText('None')
def choose_pic(self): # 界面处理 self.timer_camera.stop() self.cap.release() self.label_face.clear() self.label_result.setText('None') self.label_time.setText('0 s') self.textEdit_camera.setText('实时摄像已关闭') self.label_outputResult.clear() self.label_outputResult.setStyleSheet( "border-image: url(c://Emotion Recognition//images_test//ini.png);" ) # 使用文件选择对话框选择图片 fileName_choose, filetype = QFileDialog.getOpenFileName( self.centralwidget, "select image", self.path, # 起始路径 "图片(*.jpg;*.jpeg;*.png)") # 文件类型 self.path = fileName_choose # 保存路径 if fileName_choose != '': self.textEdit_pic.setText(fileName_choose + '文件已选中') self.label_face.setText('正在启动...\n\nleading') QtWidgets.QApplication.processEvents() # 生成模型对象 self.emotion_model = Emotion_Rec(self.model_path) # 读取背景图 tmp = open('slice.png', 'wb') tmp.write(b64decode(bgImg)) tmp.close() canvas = cv2.imread('slice.png') remove('slice.png') image = self.cv_imread(fileName_choose) # 读取选择的图片 # 计时并开始模型预测 QtWidgets.QApplication.processEvents() time_start = time.time() result = self.emotion_model.run(image, canvas, self.label_face, self.label_outputResult) time_end = time.time() # 显示结果 self.label_result.setText(result) self.label_time.setText( str(round((time_end - time_start), 3)) + ' s') else: # 选择取消,恢复界面状态 self.textEdit_pic.setText('文件未选中') gif = QMovie('c://Emotion Recognition//images_test//scan.gif') self.label_face.setMovie(gif) gif.start() self.label_outputResult.clear() # 清除画面 self.label_outputResult.setStyleSheet( "border-image: url(c://Emotion Recognition//images_test//ini.png);" ) self.label_result.setText('None') self.label_time.setText('0 s')
def button_open_camera_click(self): if self.timer_camera.isActive() == False: # 检查定时状态 flag = self.cap.open(self.CAM_NUM) # 检查相机状态 if flag == False: # 相机打开失败提示 msg = QtWidgets.QMessageBox.warning( self.centralwidget, u"Warning", u"请检测相机与电脑是否连接正确! ", buttons=QtWidgets.QMessageBox.Ok, defaultButton=QtWidgets.QMessageBox.Ok) else: # 准备运行识别程序 self.textEdit_pic.setText('file is not be selected') QtWidgets.QApplication.processEvents() self.textEdit_camera.setText('camera strat') self.label_face.setText('正在启动...\n\nleading') # 新建对象 self.emotion_model = Emotion_Rec(self.model_path) QtWidgets.QApplication.processEvents() # 打开定时器 self.timer_camera.start(30) else: # 定时器未开启,界面回复初始状态 self.timer_camera.stop() self.cap.release() self.label_face.clear() self.textEdit_camera.setText('实时摄像已关闭') self.textEdit_pic.setText('文件未选中') gif = QMovie('c://Emotion Recognition//images_test//scan.gif') self.label_face.setMovie(gif) gif.start() self.label_outputResult.clear() self.label_outputResult.setStyleSheet( "border-image: url(c://Emotion Recognition//images_test//ini.png);" ) self.label_result.setText('None') self.label_time.setText('0 s')
def button_open_camera_click(self): if self.timer_camera.isActive() == False: # 检查定时状态 flag = self.cap.open(self.CAM_NUM) # 检查相机状态 if flag == False: # 相机打开失败提示 msg = QtWidgets.QMessageBox.warning( self.centralwidget, u"Warning", u"camera connection error! ", buttons=QtWidgets.QMessageBox.Ok, defaultButton=QtWidgets.QMessageBox.Ok) else: # 准备运行识别程序 self.textEdit_pic.setText('file unchecked!') QtWidgets.QApplication.processEvents() self.textEdit_camera.setText( 'successfully turn on the camera!') self.label_face.setText('system is starting...\n\nleading') # 新建对象 self.emotion_model = Emotion_Rec(self.model_path) QtWidgets.QApplication.processEvents() # 打开定时器 self.timer_camera.start(30) else: # 定时器未开启,界面回复初始状态 self.timer_camera.stop() self.cap.release() self.label_face.clear() self.textEdit_camera.setText('camera off') self.textEdit_pic.setText('file unchecked!') gif = QMovie(':/newPrefix/images_test/scan.gif') self.label_face.setMovie(gif) gif.start() self.label_outputResult.clear() self.label_outputResult.setStyleSheet( "border-image: url(:/newPrefix/images_test/ini.png);") self.label_result.setText('None') self.label_time.setText('0 s')