Exemple #1
0
    def play(self):
        while self.camera.isOpened():
            if not self.playing:
                break
            ret, frame = self.camera.read()
            if ret:
                self.cache_frame = frame.copy()
                self.frames.appendleft(frame.copy())
                if self.flag_recognize:
                    faces = self.recognized_faces.copy()
                    for name in faces:
                        x, y, w, h = faces[name]
                        if Tool.config.getboolean('recognize',
                                                  'show_rectangle',
                                                  fallback=True):
                            cv2.rectangle(frame, (x, y), (x + w, y + h),
                                          (255, 0, 0), 1, cv2.LINE_AA)
                        if Tool.config.getboolean('recognize',
                                                  'show_name',
                                                  fallback=True):
                            cv2.putText(frame, name, (x, y - 15),
                                        cv2.FONT_HERSHEY_SIMPLEX, 1, 255, 2)
                        if Tool.config.getboolean('recognize',
                                                  'show_desc',
                                                  fallback=True):
                            desc = self.face_desc.get(name, '')
                            if desc:
                                cv2.putText(frame, desc, (10, 30),
                                            cv2.FONT_HERSHEY_SIMPLEX, 1, 255,
                                            2)
                img = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
                image = QImage(img, img.shape[1], img.shape[0],
                               img.shape[1] * 3, QImage.Format_RGB888)
                pix_map = QPixmap.fromImage(image)
                pix_map = pix_map.scaled(Tool.get_win_width() - 130,
                                         Tool.get_win_height() - 20,
                                         Qt.KeepAspectRatio)
                self.lbl_viewer.setPixmap(pix_map)

        self.lbl_viewer.clear()
        self.camera.release()
Exemple #2
0
    def init_ui(self):
        self.setFixedSize(Tool.get_win_width(), Tool.get_win_height())
        qr = self.frameGeometry()
        cp = QDesktopWidget().availableGeometry().center()
        qr.moveCenter(cp)
        self.move(qr.topLeft())
        self.setWindowIcon(QIcon('icons/icon.png'))
        self.setWindowTitle('客户端')

        self.lbl_viewer = QLabel(self)
        self.lbl_viewer.setGeometry(
            QRect(10, 10,
                  Tool.get_win_width() - 130,
                  Tool.get_win_height() - 20))
        self.lbl_viewer.setText('没有图像')
        font = QFont()
        font.setPointSize(20)
        self.lbl_viewer.setFont(font)
        self.lbl_viewer.setAlignment(Qt.AlignCenter)
        self.lbl_viewer.setFrameShape(QFrame.StyledPanel)

        self.btn_open_camera = QPushButton(self)
        self.btn_open_camera.setGeometry(
            QRect(Tool.get_win_width() - 110, 10, 100, 26))
        self.btn_open_camera.setText('打开摄像头')
        self.btn_open_camera.clicked.connect(self.btn_click)

        self.btn_close_camera = QPushButton(self)
        self.btn_close_camera.setGeometry(
            QRect(Tool.get_win_width() - 110, 46, 100, 26))
        self.btn_close_camera.setText('关闭摄像头')
        self.btn_close_camera.setDisabled(True)
        self.btn_close_camera.clicked.connect(self.btn_click)

        self.cb_recognize = QCheckBox(self)
        self.cb_recognize.setText('启动识别')
        self.cb_recognize.setDisabled(True)
        self.cb_recognize.setGeometry(
            QRect(Tool.get_win_width() - 108, 82, 100, 26))
        self.cb_recognize.clicked.connect(self.cb_click)

        self.btn_capture = QPushButton(self)
        self.btn_capture.setGeometry(
            QRect(Tool.get_win_width() - 110,
                  Tool.get_win_height() - 366, 100, 26))
        self.btn_capture.setText('截屏')
        self.btn_capture.setDisabled(True)
        self.btn_capture.clicked.connect(self.btn_click)

        self.btn_capture_1 = QPushButton(self)
        self.btn_capture_1.setGeometry(
            QRect(Tool.get_win_width() - 110,
                  Tool.get_win_height() - 330, 100, 100))
        self.btn_capture_1.setIconSize(QSize(98, 98))
        self.btn_capture_1.setDisabled(True)
        self.btn_capture_1.clicked.connect(self.btn_click)
        self.btn_capture_2 = QPushButton(self)
        self.btn_capture_2.setGeometry(
            QRect(Tool.get_win_width() - 110,
                  Tool.get_win_height() - 220, 100, 100))
        self.btn_capture_2.setIconSize(QSize(98, 98))
        self.btn_capture_2.setDisabled(True)
        self.btn_capture_2.clicked.connect(self.btn_click)
        self.btn_capture_3 = QPushButton(self)
        self.btn_capture_3.setGeometry(
            QRect(Tool.get_win_width() - 110,
                  Tool.get_win_height() - 110, 100, 100))
        self.btn_capture_3.setIconSize(QSize(98, 98))
        self.btn_capture_3.setDisabled(True)
        self.btn_capture_3.clicked.connect(self.btn_click)