class mainInterface(QWidget): # 定义信号 processFinished = pyqtSignal(dict) def __init__(self): """ 初始化 :return: null """ # 超类初始化 super().__init__() # UI初始化 self.ui = Ui_mainWidget() self.ui.setupUi(self) self.grabKeyboard() self.setMouseTracking(True) self.setWindowFlags(Qt.FramelessWindowHint) self.setWindowIcon(QIcon('OCR.ico')) # 初始化相机 self.camera = QCamera() self.imageCapture = QCameraImageCapture(self.camera) self.viewsetting = QCameraViewfinderSettings() self.initimplement() # 初始化标题栏 self.initTitleBar() # 初始化系统托盘 self.tray = QSystemTrayIcon() self.tray.setIcon(QIcon('OCR.ico')) self.initTray() # OCR识别部分 self.OCR = ocr() self.OCR.setappid('1257206643') self.OCR.setsecretid('AKIDFTddWEg9Ncsz0sE7oOpBNOExdDdeCUJ3') self.OCR.setsecretkey('FQitsgUND8yfrZK0RrBMOJB5tWhCm5Ol') # 初始化登录部分 self.logWidget = QWidget() self.logui = Ui_Form() self.logui.setupUi(self.logWidget) self.logWidget.setWindowFlags(Qt.FramelessWindowHint) self.logWidget.setWindowModality(Qt.ApplicationModal) self.logui.close_btn.clicked.connect(self.logWidget.close) # 初始化变量 self.mousePressd = False self.mousePoint = None self.result = {} self.isFirst = False self.ocrType = ocrType.ocr_general # 默认为印刷体识别 # 初始化字定义信号连接 self.processFinished.connect(self.updateOCRInfo) self.ui.btn_login.clicked.connect(self.logWidget.show) self.ui.comboBox_choose.currentIndexChanged.connect(self.changeocrType) def initTitleBar(self): """ 初始化标题栏 :return: null """ self.ui.frame.setStyleSheet( "QFrame#frame{background-color:rgb(244, 76, 76);}") self.ui.label_logo.setStyleSheet( "QLabel{border-image:url(./image/ocr.png);}") self.ui.label_title.setStyleSheet( "QLabel{border-image:url(./image/iOCR.png);}") self.ui.comboBox_choose.setStyleSheet( "QComboBox {border-radius:15px;border: 2px solid #4AFFF4;font-family:'楷体';font-size:20px;}" "QComboBox QAbstractItemView::item{height:50px;width:200px;}" "QComboBox::down-arrow{image: url(./image/arrow.png);width:25px;height:25px;}" "QComboBox::drop-down {subcontrol-origin: padding;subcontrol-position:top right;border:none;margin-right:30px;}" "QComboBox::down-arrow:hover{image:url(./image/arrow_hover.png);width:25px;height:25px;}" "QComboBox::down-arrow:on {top: 1px;left: 1px;}") self.ui.comboBox_choose.insertItem(0, ' 印刷体识别') self.ui.comboBox_choose.insertItem(1, ' 手写体识别') self.ui.comboBox_choose.insertItem(2, ' 身份证识别') self.ui.comboBox_choose.insertItem(3, ' 名片识别') self.ui.comboBox_choose.insertItem(4, ' 银行卡识别') self.ui.btn_login.setStyleSheet( "QPushButton{border-image:url(./image/default-portrait.png);}") self.ui.btn_setting.setStyleSheet( "QPushButton{border-image:url(./image/settings.png);}" "QPushButton:hover{border-image:url(./image/qcconfig-hover.png);}") self.ui.btn_min.setStyleSheet( "QPushButton{border-image:url(./image/mini_new.png);}" "QPushButton:hover{border-image:url(./image/mini_hover_new.png);}") self.ui.btn_close.setStyleSheet( "QPushButton{border-image:url(./image/close.png);}" "QPushButton:hover{border-image:url(./image/close-hover.png);}") self.ui.checkBox_cam.setStyleSheet( "QCheckBox{spacing: 5px;font-size: 24px;vertical-align:middle}" "QCheckBox::indicator { width: 45px;height: 45px;}" "QCheckBox::indicator::unchecked {image: url(./image/close_cam.png);}" "QCheckBox::indicator::checked { image: url(./image/open_cam.png);}" ) self.ui.captureBtn.setStyleSheet( "QPushButton{border-style: outset;border-width: 2px;border-color: rgb(82,215,100);border-radius: 5px;font-size: 24px;}" "QPushButton:pressed{background-color: rgb(176,215,181);border-style: inset;}" ) self.ui.checkBox_cam.setChecked(True) self.ui.btn_close.clicked.connect(lambda: qApp.quit()) self.ui.btn_min.clicked.connect(self.miniToTray) self.ui.checkBox_cam.stateChanged.connect(self.camControl) def initTray(self): """ 初始化系统托盘信息 :return: """ tray_menu = QMenu() restoreAction = QAction('&Show', self) quitAction = QAction('&Quit', self) tray_menu.addAction(restoreAction) tray_menu.addAction(quitAction) self.tray.setContextMenu(tray_menu) restoreAction.triggered.connect(self.trayActivatedEvent) quitAction.triggered.connect(qApp.quit) self.tray.activated.connect(self.trayActivatedEvent) def initimplement(self): """ 初始化实现端口 :return: ui """ camInfo = QCameraInfo(self.camera) if camInfo.defaultCamera().isNull(): QMessageBox.warning(self, 'Warning', 'No available camera!', QMessageBox.Ok) return -1 else: self.ui.caputurePhoto.setText(camInfo.description()) self.camera.setViewfinder(self.ui.cameraShow) self.camera.setCaptureMode(QCamera.CaptureStillImage) self.camera.load() resolution = self.camera.supportedViewfinderResolutions() if len(resolution) != 0: if QSize(640, 480) in resolution: self.viewsetting.setResolution(QSize(640, 480)) elif QSize(640, 360) in resolution: self.viewsetting.setResolution(QSize(640, 360)) else: self.viewsetting.setResolution(resolution[0]) self.camera.setViewfinderSettings(self.viewsetting) # ------------------------------Note-------------------------------- # 此种方法利用摄像头准备捕捉图像的状态来进行捕捉图像,readyForCapture # 为true时,才进行捕捉图像,详见下面捕捉函数槽函数。这种方法将进行不 # 停的捕捉,将每次捕捉的相邻图像进行图像相似度判断。当图像相似度低于 # 阈值时,认定为新图像,才进行OCR识别。否则仅捕捉图像而不进行识别。当 # 然捕捉图像速度过于太快时,可以用定时器,每隔0.5秒,去检查readyFor # Capture状态位,进而有效控制程序资源。 # 本应用中采用按键捕捉方式,非自动,详见下面按键捕捉事件 # ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ # self.imageCapture.readyForCaptureChanged.connect(self.captureimage) self.camera.start() self.ui.caputurePhoto.setScaledContents(True) self.imageCapture.setCaptureDestination( QCameraImageCapture.CaptureToBuffer) self.imageCapture.imageCaptured.connect(self.displayimage) self.ui.captureBtn.clicked.connect(self.openDlg) def displayimage(self, num, image): """ 显示图形 :param num: number :param image: image :return: null """ self.ui.caputurePhoto.setPixmap(QPixmap.fromImage(image)) self.ui.ocrInfo.setText('识别中......') t = threading.Thread(target=self.ocrForImage, args=(image, )) t.start() # def captureimage(self, state): # """ # 捕捉图像槽函数 # :state: 状态变量 # :return: null # """ # if state is True: # self.camera.searchAndLock() # self.imageCapture.capture() # self.camera.unlock() # def saveimage(self): # """ # 保存图像槽函数 # :return: null # """ # pix = QPixmap(self.ui.caputurePhoto.pixmap()) # if pix: # pix.save(r'D://1.png', 'PNG') # QMessageBox.information(self, 'Message', 'Capture Successfully', QMessageBox.Ok) def ocrForImage(self, image): """ 为截取的图片进行ocr识别 :param image: QImage :return: null """ # Note:子线程里不能对ui界面做改动,ui界面修改只能在主线程中修改,下面注释的做法是错误的 # self.ui.ocrInfo.setText('识别中......') byte = QByteArray() buffer = QBuffer(byte) buffer.open(QIODevice.WriteOnly) image.save(buffer, 'PNG') if self.ocrType == ocrType.ocr_general: self.result = self.OCR.client.general_detect( CIBuffers([byte.data()])) elif self.ocrType == ocrType.ocr_handwriting: self.result = self.OCR.client.handwriting_detect( CIBuffers([byte.data()])) elif self.ocrType == ocrType.ocr_idcard: self.result = self.OCR.client.idcard_detect( CIBuffers([byte.data()]), 0) elif self.ocrType == ocrType.ocr_namecard: self.result = self.OCR.client.namecard_detect( CIBuffers([byte.data()]), 0) elif self.ocrType == ocrType.ocr_bankcard: self.result = self.OCR.client.bankcard_detect( CIBuffers([byte.data()])) else: pass self.processFinished.emit(self.result) def updateOCRInfo(self, res): """ 将ocr识别结果显示在信息框中 :param res: :return: """ if self.ocrType == ocrType.ocr_general or self.ocrType == ocrType.ocr_handwriting: if res['code'] == 0 and res['message'] == 'OK': self.ui.ocrInfo.setText('OK') ocrInfo = [] for i in range(len(self.result['data']['items'])): ocrInfo.append( self.result['data']['items'][i]['itemstring']) self.ui.ocrInfo.setText(''.join(ocrInfo)) else: self.ui.ocrInfo.setText('识别失败!') elif self.ocrType == ocrType.ocr_bankcard: if res['code'] == 0 and res['message'] == 'OK': self.ui.ocrInfo.setText('OK') ocrInfo = [] for i in range(len(self.result['data']['items'])): ocrInfo.append(self.result['data']['items'][i]['item']) ocrInfo.append(':') ocrInfo.append( self.result['data']['items'][i]['itemstring']) ocrInfo.append('\n') self.ui.ocrInfo.setText(''.join(ocrInfo)) else: self.ui.ocrInfo.setText('识别失败!') elif self.ocrType == ocrType.ocr_idcard: if res['result_list'][0]['code'] == 0 and res['result_list'][0][ 'message'] == 'OK': self.ui.ocrInfo.setText('OK') ocrInfo = [] ocrInfo_keys = list( self.result['result_list'][0]['data'].keys()) ocrInfo_values = list( self.result['result_list'][0]['data'].values()) for i in range( len(self.result['result_list'][0]['data']) // 2): ocrInfo.append(ocrInfo_keys[i]) ocrInfo.append(':') ocrInfo.append(ocrInfo_values[i]) ocrInfo.append('\n') self.ui.ocrInfo.setText(''.join(ocrInfo)) else: self.ui.ocrInfo.setText('识别失败!') elif self.ocrType == ocrType.ocr_namecard: if res['result_list'][0]['code'] == 0 and res['result_list'][0][ 'message'] == 'OK': self.ui.ocrInfo.setText('OK') ocrInfo = [] for i in range(len(self.result['result_list'][0]['data'])): ocrInfo.append( self.result['result_list'][0]['data'][i]['item']) ocrInfo.append(':') ocrInfo.append( self.result['result_list'][0]['data'][i]['value']) ocrInfo.append('\n') self.ui.ocrInfo.setText(''.join(ocrInfo)) else: self.ui.ocrInfo.setText('识别失败!') else: pass def camControl(self, state): """ 槽函数 控制相机开关 :param state: checkbox开关状态 :return:null """ if state == Qt.Unchecked: self.ui.cameraShow.setUpdatesEnabled(False) elif state == Qt.Checked: self.ui.cameraShow.setUpdatesEnabled(True) else: return -1 def miniToTray(self): """ 槽函数 最小化到系统托盘 :return:null """ if not self.tray.isVisible(): self.tray.show() if self.tray.isVisible(): if self.isFirst is False: QMessageBox.information( self, "Systray", "The program will keep running in the " "system tray. To terminate the program, " "choose <b>Quit</b> in the context menu " "of the system tray entry.") self.isFirst = True self.hide() def trayActivatedEvent(self, reason): """ 槽函数 响应点击托盘图标 :param reason: 响应原因 :return: null """ if reason == QSystemTrayIcon.Context: pass else: self.tray.hide() self.show() def openDlg(self): """ 槽函数 打开对话框选取文件 :return:文件名 """ filename, filetype = QFileDialog.getOpenFileName( self, '选取图片', path.expanduser('~'), "Image Files (*.png *.jpg *.bmp)") if filename: if QFile(filename).size() >= 6291456: QMessageBox.information(self, '打开图片', '选择图片大于6MB大小,暂不支持识别,请重新选择。') self.openDlg() else: self.displayimage(0, QImage(filename)) def keyPressEvent(self, e): """ 槽函数 键盘按键响应事件 :param e: 按键事件 :return: null """ if e.key() == Qt.Key_Space: if self.imageCapture.isReadyForCapture(): self.camera.searchAndLock() self.imageCapture.capture() self.camera.unlock() def mouseMoveEvent(self, e): """ 槽函数 定义鼠标移动事件 :param e: QMouseEvent :return: null """ if (e.buttons() == Qt.LeftButton) and self.mousePressd: self.move(e.globalPos() - self.mousePoint) e.accept() def mousePressEvent(self, e): """ 槽函数 定义鼠标按下事件 :param e: QMouseEvent :return: null """ if e.button() == Qt.LeftButton: self.mousePressd = True self.mousePoint = e.globalPos() - self.pos() e.accept() def mouseReleaseEvent(self, e): """ 槽函数 定义鼠标松开事件 :param e: QMouseEvent :return: null """ self.mousePressd = False def changeocrType(self, index): """ 槽函数 改变ocr识别类型 :param index: int :return: null """ if index == 0: self.ocrType = ocrType.ocr_general elif index == 1: self.ocrType = ocrType.ocr_handwriting elif index == 2: self.ocrType = ocrType.ocr_idcard elif index == 3: self.ocrType = ocrType.ocr_namecard elif index == 4: self.ocrType = ocrType.ocr_bankcard else: pass
class Window(QWidget): # конструктор формы def __init__(self): super().__init__() self._Client = Biometric_Client( url='https://expasoft.com', port=2133, subscription_key='9fc9474b4bd16b492276eee41763a3cb') self.resize(800, 600) self.setObjectName("FormMain") self.setWindowTitle("БиоСКУД Archivist") self.labelHumans = QtWidgets.QLabel(self) self.labelHumans.setObjectName("labelHumans") self.labelHumans.setText("Профили сотрудников") self.labelHumans.setGeometry(QtCore.QRect(80, 15, 181, 21)) font = QtGui.QFont() font.setPointSize(12) self.labelHumans.setFont(font) self.labelPhotos = QtWidgets.QLabel(self) self.labelPhotos.setObjectName("labelPhotos") self.labelPhotos.setText("Фото сотрудника") self.labelPhotos.setGeometry(QtCore.QRect(390, 15, 181, 21)) font = QtGui.QFont() font.setPointSize(12) self.labelPhotos.setFont(font) self.listViewHumans = QtWidgets.QListWidget(self) self.listViewHumans.setObjectName("listViewHumans") self.listViewHumans.setGeometry(QtCore.QRect(10, 50, 291, 531)) self.listViewHumans.setIconSize(QtCore.QSize(200, 200)) self.listViewHumans.itemClicked.connect(self.LoadProfile) self.listViewPhotos = QtWidgets.QListWidget(self) self.listViewPhotos.setObjectName("listViewPhotos") self.listViewPhotos.setGeometry(QtCore.QRect(310, 50, 291, 281)) self.listViewPhotos.setIconSize(QtCore.QSize(150, 150)) self.labelName = QLabel(self) self.labelName.setText("ФИО:") self.labelName.move(310, 355) self.lineName = QLineEdit(self) self.lineName.resize(140, 25) self.lineName.move(350, 350) self.labelTag = QLabel(self) self.labelTag.setText("Пост:") self.labelTag.move(310, 385) self.lineTag = QLineEdit(self) self.lineTag.resize(140, 25) self.lineTag.move(350, 380) self.pushButtonAddProfile = QtWidgets.QPushButton(self) self.pushButtonAddProfile.setGeometry(QtCore.QRect(310, 420, 181, 51)) self.pushButtonAddProfile.setObjectName("pushButtonAddProfile") self.pushButtonAddProfile.setText("Добавить профиль") self.pushButtonAddProfile.clicked.connect(self.AddProfile) self.pushButtonUpdateProfile = QtWidgets.QPushButton(self) self.pushButtonUpdateProfile.setGeometry( QtCore.QRect(310, 475, 181, 51)) self.pushButtonUpdateProfile.setObjectName("pushButtonAddProfile") self.pushButtonUpdateProfile.setText("Обновить профиль") self.pushButtonUpdateProfile.clicked.connect(self.UpdateProfile) self.pushButtonDelProfile = QtWidgets.QPushButton(self) self.pushButtonDelProfile.setGeometry(QtCore.QRect(310, 530, 181, 51)) self.pushButtonDelProfile.setObjectName("pushButtonDelProfile") self.pushButtonDelProfile.setText("Удалить профиль") self.pushButtonDelProfile.clicked.connect(self.DelProfile) self.CameraStream = QVideoWidget(self) self.CameraStream.setObjectName("videoCameraStream") self.CameraStream.setGeometry(QtCore.QRect(610, 25, 180, 200)) self.device = QCamera.availableDevices()[0] self.camera = QCamera(self.device) self.camera.setViewfinder(self.CameraStream) self.camera.setCaptureMode(QCamera.CaptureStillImage) self.imageCapture = QCameraImageCapture(self.camera) self.imageCapture.imageSaved.connect(self.AddPhotoEnd) self.camera.start() self.pushButtonAddPhoto = QtWidgets.QPushButton(self) self.pushButtonAddPhoto.setObjectName("pushButtonAddPhoto") self.pushButtonAddPhoto.setText("Добавить фото") self.pushButtonAddPhoto.setGeometry(QtCore.QRect(610, 225, 181, 51)) self.pushButtonAddPhoto.clicked.connect(self.AddPhotoBegin) self.pushButtonDelPhoto = QtWidgets.QPushButton(self) self.pushButtonDelPhoto.setObjectName("pushButtonDelPhoto") self.pushButtonDelPhoto.setText("Удалить фото") self.pushButtonDelPhoto.setGeometry(QtCore.QRect(610, 280, 181, 51)) self.pushButtonDelPhoto.clicked.connect(self.DelPhoto) self.LoadProfiles() # загружаем список сотрудников def LoadProfiles(self): self.listViewHumans.clear() AllProfiles = self._Client.get_profiles_ids()['result'] if len(AllProfiles) != 0: for profile in AllProfiles: item = QtWidgets.QListWidgetItem() #item.setText(str(profile)) if (GetInfo(str(profile)) != None): item.setText(GetInfo(str(profile))["name"]) item.setToolTip(str(profile)) AllPhoto = self._Client.get_profile_images_ids( profile)['result'] if len(AllPhoto) != 0: FileName = "img/" + str(profile) + '-' + str( AllPhoto[0]) + '.jpg' self._Client.get_profile_image(profile, AllPhoto[0], FileName) item.setIcon(QtGui.QIcon(FileName)) self.listViewHumans.addItem(item) # загружаем профиль def LoadProfile(self, item): self.listViewPhotos.clear() #idProfile = int(item.text()) idProfile = int(item.toolTip()) AllPhoto = self._Client.get_profile_images_ids(idProfile)['result'] for photo in AllPhoto: FileName = "img/" + str(idProfile) + '-' + str(photo) + '.jpg' self._Client.get_profile_image(idProfile, photo, FileName) item = QtWidgets.QListWidgetItem() item.setText(str(photo)) item.setIcon(QtGui.QIcon(FileName)) self.listViewPhotos.addItem(item) infoProfile = JsonDataBase.GetInfo(idProfile) if infoProfile != None: self.lineName.setText(infoProfile['name']) self.lineTag.setText(infoProfile['tag']) else: self.lineName.setText("") self.lineTag.setText("") # добавляем профиль def AddProfile(self): profile_name = self.lineName.text() profile_post = self.lineTag.text() Id_Profile = self._Client.add_profile(profile_name, '01.01.1111', 'm', tags="").pop('result') JsonDataBase.AddInfo(Id_Profile, profile_name, '01.01.1111', "m", profile_post) self.LoadProfiles() # обновляем профиль def UpdateProfile(self): Id_Profile = self.listViewHumans.currentItem().toolTip() profile_name = self.lineName.text() profile_post = self.lineTag.text() if (JsonDataBase.GetInfo(Id_Profile) != None): JsonDataBase.UpdateInfo(Id_Profile, name=profile_name, tag=profile_post) else: JsonDataBase.AddInfo(Id_Profile, name=profile_name, tag=profile_post) self.LoadProfiles() # удаляем профиль def DelProfile(self): Id_Profile = self.listViewHumans.currentItem().toolTip() self._Client.delete_profile(Id_Profile) JsonDataBase.DelInfo(Id_Profile) self.LoadProfiles() # добавляем фото def AddPhotoBegin(self): if self.imageCapture.isReadyForCapture(): imgName = os.getcwd() + "\img\currentPhoto.jpg" self.camera.searchAndLock() self.imageCapture.capture(imgName) self.camera.unlock() def AddPhotoEnd(self): print(0) imgName = os.getcwd() + "\img\currentPhoto.jpg" imgName0 = os.getcwd() + "\img\currentPhoto0.jpg" idProfile = int(self.listViewHumans.currentItem().toolTip()) self._Client.get_aligned_faces(imgName, "img\currentPhoto") self._Client.enroll_profile_face(idProfile, imgName0) self.LoadProfile(self.listViewHumans.currentItem()) # удаляем фото def DelPhoto(self): #Id_Profile = self.listViewHumans.currentItem().text() Id_Profile = self.listViewHumans.currentItem().toolTip() Id_Photo = self.listViewPhotos.currentItem().text() self._Client.delete_image(Id_Profile, Id_Photo) self.LoadProfile(self.listViewHumans.currentItem())
class Window(QWidget): _Constant_recognition = 0.8 # конструктор формы def __init__(self): super().__init__() self._Client = Biometric_Client(url='https://expasoft.com', port=2133, subscription_key='9fc9474b4bd16b492276eee41763a3cb') self.imgName = os.getcwd() + "\img\currentPhoto.jpg" self.imgName0 = os.getcwd() + "\img\currentPhoto0.jpg" self.imgName1 = os.getcwd() + "\img\dbPhoto0.jpg" self.setObjectName("FormMain") self.setWindowTitle("БиоСКУД Watchman") self.resize(1024, 600) self.groupBoxCamera = QtWidgets.QGroupBox(self) self.groupBoxCamera.setObjectName("groupBoxCamera") self.groupBoxCamera.setTitle("") self.groupBoxCamera.setGeometry(QtCore.QRect(10, 10, 500, 371)) self.labelCameraTitle = QtWidgets.QLabel(self.groupBoxCamera) self.labelCameraTitle.setObjectName("labelCameraTitle") self.labelCameraTitle.setText("Изображение с камеры") self.labelCameraTitle.setGeometry(QtCore.QRect(160, 10, 181, 21)) font = QtGui.QFont() font.setPointSize(12) self.labelCameraTitle.setFont(font) self.CameraStream = QVideoWidget(self) self.CameraStream.setObjectName("videoCameraStream") self.CameraStream.setGeometry(QtCore.QRect(10, 50, 481, 261)) self.CameraStream.setMinimumSize(QtCore.QSize(241, 0)) self.pushButtonRecognition = QtWidgets.QPushButton(self.groupBoxCamera) self.pushButtonRecognition.setObjectName("pushButtonRecognition") self.pushButtonRecognition.setText("Распознать") self.pushButtonRecognition.setGeometry(QtCore.QRect(10, 310, 481, 51)) self.pushButtonRecognition.clicked.connect(self.identifyPersonBegin) self.pushButtonLog = QtWidgets.QPushButton(self) self.pushButtonLog.setObjectName("pushButtonLog") self.pushButtonLog.setText("Журнал") self.pushButtonLog.setGeometry(QtCore.QRect(10, 460, 121, 61)) self.pushButtonLog.clicked.connect(self.OpenLogFile) self.pushButtonDb = QtWidgets.QPushButton(self) self.pushButtonDb.setObjectName("pushButtonDb") self.pushButtonDb.setText("База данных") self.pushButtonDb.setGeometry(QtCore.QRect(10, 390, 121, 61)) self.pushButtonDb.clicked.connect(self.OpenArchivist) self.groupBoxRecognition = QtWidgets.QGroupBox(self) self.groupBoxRecognition.setObjectName("groupBoxRecognition") self.groupBoxRecognition.setTitle("") self.groupBoxRecognition.setGeometry(QtCore.QRect(520, 10, 500, 581)) self.pushButtonExit = QtWidgets.QPushButton(self) self.pushButtonExit.setObjectName("pushButtonExit") self.pushButtonExit.setText("Выйти") self.pushButtonExit.setGeometry(QtCore.QRect(10, 530, 121, 61)) self.pushButtonExit.clicked.connect(self.ExitProgream) self.labelPersonName = QtWidgets.QLabel(self.groupBoxRecognition) self.labelPersonName.setObjectName("labelPersonName") self.labelPersonName.setText("") self.labelPersonName.setGeometry(QtCore.QRect(20, 320, 271, 31)) font = QtGui.QFont() font.setPointSize(16) self.labelPersonName.setFont(font) self.labelCurrentPhoto = QtWidgets.QLabel(self.groupBoxRecognition) self.labelCurrentPhoto.setObjectName("labelCurrentPhoto") self.labelCurrentPhoto.setText("") self.labelCurrentPhoto.setGeometry(QtCore.QRect(10, 40, 241, 261)) self.labelCurrentPhoto.setMinimumSize(QtCore.QSize(241, 0)) self.labelCurrentPhoto.setAlignment(QtCore.Qt.AlignCenter) self.labelPersonJob = QtWidgets.QLabel(self.groupBoxRecognition) self.labelPersonJob.setObjectName("labelPersonJob") self.labelPersonJob.setText("") self.labelPersonJob.setGeometry(QtCore.QRect(20, 360, 171, 21)) font = QtGui.QFont() font.setPointSize(12) self.labelPersonJob.setFont(font) self.labelPersonInf = QtWidgets.QLabel(self.groupBoxRecognition) self.labelPersonInf.setObjectName("labelPersonJob") self.labelPersonInf.setText("") self.labelPersonInf.setGeometry(QtCore.QRect(20, 400, 171, 21)) font = QtGui.QFont() font.setPointSize(8) self.labelPersonInf.setFont(font) self.labelAccess = QtWidgets.QLabel(self.groupBoxRecognition) self.labelAccess.setObjectName("labelAccess") self.labelAccess.setText("<html><head/><body><p align=\"center\">Допущен</p></body></html>") self.labelAccess.setGeometry(QtCore.QRect(10, 490, 481, 81)) palette = QtGui.QPalette() brush = QtGui.QBrush(QtGui.QColor(76, 197, 32)) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush) self.labelAccess.setPalette(palette) font = QtGui.QFont() font.setPointSize(16) font.setBold(True) font.setWeight(75) self.labelAccess.setFont(font) self.labelAccess.setAcceptDrops(False) self.labelAccess.setAutoFillBackground(True) self.labelAccess.setFrameShape(QtWidgets.QFrame.NoFrame) self.labelAccess.setFrameShadow(QtWidgets.QFrame.Plain) self.labelAccess.setTextFormat(QtCore.Qt.AutoText) self.labelAccess.setTextInteractionFlags(QtCore.Qt.LinksAccessibleByMouse) self.labelDbPhoto = QtWidgets.QLabel(self.groupBoxRecognition) self.labelDbPhoto.setObjectName("labelDbPhoto") self.labelDbPhoto.setText("") self.labelDbPhoto.setGeometry(QtCore.QRect(250, 40, 241, 261)) self.labelDbPhoto.setMinimumSize(QtCore.QSize(241, 0)) self.labelDbPhoto.setAlignment(QtCore.Qt.AlignCenter) self.labelCurrentPhotoTitle = QtWidgets.QLabel(self.groupBoxRecognition) self.labelCurrentPhotoTitle.setObjectName("labelCurrentPhotoTitle") self.labelCurrentPhotoTitle.setText("Текущее фото") self.labelCurrentPhotoTitle.setGeometry(QtCore.QRect(80, 10, 111, 21)) font = QtGui.QFont() font.setPointSize(12) self.labelCurrentPhotoTitle.setFont(font) self.labelDbPhotoTitle = QtWidgets.QLabel(self.groupBoxRecognition) self.labelDbPhotoTitle.setObjectName("labelDbPhotoTitle") self.labelDbPhotoTitle.setText("Фото в базе") self.labelDbPhotoTitle.setGeometry(QtCore.QRect(320, 10, 111, 21)) font = QtGui.QFont() font.setPointSize(12) self.labelDbPhotoTitle.setFont(font) self.device = QCamera.availableDevices()[0] self.camera = QCamera(self.device) self.camera.setViewfinder(self.CameraStream) self.camera.setCaptureMode(QCamera.CaptureStillImage) self.imageCapture=QCameraImageCapture(self.camera) self.imageCapture.imageSaved.connect(self.identifyPersonEnd) self.camera.start() # идентификация человека (фото) def identifyPersonBegin(self): if self.imageCapture.isReadyForCapture(): #imgName = os.getcwd() + "\img\currentPhoto.jpg" self.camera.searchAndLock() self.imageCapture.capture(self.imgName) self.camera.unlock() # идентификация человека (алгоритм) def identifyPersonEnd(self): self._Client.get_aligned_faces(self.imgName, "img\currentPhoto") id_person = self._Client.identify_profile_by_face(self.imgName0, 1, 0).pop("result")[0] self._Client.get_profile_image(id_person['profile_id'], id_person['image_id'],self.imgName1) self.labelCurrentPhoto.setPixmap(QtGui.QPixmap(self.imgName0)) self.labelDbPhoto.setPixmap(QtGui.QPixmap(self.imgName1)) profile = JsonDataBase.GetInfo(id_person['profile_id']) if profile != None: self.labelPersonName.setText(profile['name']) self.labelPersonJob.setText(profile['tag']) else: self.labelPersonName.setText(profile['']) self.labelPersonJob.setText(profile['']) if id_person['score'] > self._Constant_recognition : palette = QtGui.QPalette() brush = QtGui.QBrush(QtGui.QColor(255, 22, 46)) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush) self.labelAccess.setPalette(palette) self.labelAccess.setText("<html><head/><body><p align=\"center\">Недопущен</p></body></html>") else: palette = QtGui.QPalette() brush = QtGui.QBrush(QtGui.QColor(76, 197, 32)) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush) self.labelAccess.setPalette(palette) self.labelAccess.setText("<html><head/><body><p align=\"center\">Допущен</p></body></html>") self.labelPersonInf.setText('id= ' + str(id_person['profile_id'])+' score= '+str(id_person['score'])) # открыть управление базой данных def OpenArchivist(self): self.archivist = Archivist.Window() self.archivist.show() # открыть файл логов def OpenLogFile(self): os.system("log.txt") # выйти из программы def ExitProgream(self): self.camera.stop() self.close()