Exemplo n.º 1
0
 def __init__(self, img_rec: ImageRecognition, res_wid: ResultWid,
              sig_res_wid: SingleResultWid):
     super(CameraMainWin, self).__init__()
     self.setupUi(self)
     # 设置图像处理实例和跳转实例
     self.img_rec = img_rec
     self.res_wid = res_wid
     self.sig_res_wid = sig_res_wid
     # camera设置
     self.camera = QCamera()
     self.camera.setCaptureMode(QCamera.CaptureViewfinder)
     self.cameraOpened = False  # 设置相机打开状态为未打开
     # 设置取景器分辨率
     view_finder_settings = QCameraViewfinderSettings()
     self.camera.setViewfinderSettings(view_finder_settings)
     # 初始化取景器
     self.viewCamera = QtMultimediaWidgets.QCameraViewfinder(self)
     self.camera.setViewfinder(self.viewCamera)
     self.cameraLayout.addWidget(self.viewCamera)  # 取景器放置到预留的布局中
     # 设置图像捕获
     self.capImg = QCameraImageCapture(self.camera)
     self.capImg.setCaptureDestination(QCameraImageCapture.CaptureToBuffer)
     self.capImg.imageCaptured.connect(self._process_captured_image)
     # 绑定按钮槽函数
     self.cameraButton.clicked.connect(self.switch_camera)
     self.captureButton.clicked.connect(self.take_pic)
     self.loadButton.clicked.connect(self.load_file)
     self.reconitionButton.clicked.connect(self.load_path)
     self.chg_mod_Button.clicked.connect(self.change_model)
Exemplo n.º 2
0
    def __init__(self):
        """MainWindow constructor"""
        super().__init__()
        base_widget = qtw.QWidget()
        base_widget.setLayout(qtw.QHBoxLayout())
        notebook = qtw.QTabWidget()
        base_widget.layout().addWidget(notebook)
        self.file_list = qtw.QListWidget()
        base_widget.layout().addWidget(self.file_list)
        self.setCentralWidget(base_widget)

        toolbar = self.addToolBar('Transport')
        record_act = toolbar.addAction('Rec')
        stop_act = toolbar.addAction('Stop')
        play_act = toolbar.addAction('Play')
        pause_act = toolbar.addAction('Pause')

        self.video_dir = qtc.QDir.home()
        if not self.video_dir.cd('captains_log'):
            qtc.QDir.home().mkdir('captains_log')
            self.video_dir.cd('captains_log')

        self.refresh_video_list()

        self.player = qtmm.QMediaPlayer()
        self.video_widget = qtmmw.QVideoWidget()
        self.player.setVideoOutput(self.video_widget)

        notebook.addTab(self.video_widget, 'Play')
        play_act.triggered.connect(self.player.play)
        pause_act.triggered.connect(self.player.pause)
        stop_act.triggered.connect(self.player.stop)
        play_act.triggered.connect(
            lambda: notebook.setCurrentWidget(self.video_widget))
        self.file_list.itemDoubleClicked.connect(self.on_file_selected)
        self.file_list.itemDoubleClicked.connect(
            lambda: notebook.setCurrentWidget(self.video_widget))

        self.camera = self.camera_check()
        if not self.camera:
            self.show()
            return
        self.camera.setCaptureMode(qtmm.QCamera.CaptureVideo)
        self.cvf = qtmmw.QCameraViewfinder()
        self.camera.setViewfinder(self.cvf)
        notebook.addTab(self.cvf, 'Record')
        self.camera.start()

        self.recorder = qtmm.QMediaRecorder(self.camera)

        settings = self.recorder.videoSettings()
        settings.setResolution(640, 480)
        settings.setFrameRate(24.0)
        settings.setQuality(qtmm.QMultimedia.VeryHighQuality)
        self.recorder.setVideoSettings(settings)

        record_act.triggered.connect(self.record)
        record_act.triggered.connect(
            lambda: notebook.setCurrentWidget(self.cvf))
        pause_act.triggered.connect(self.recorder.pause)
        stop_act.triggered.connect(self.recorder.stop)
        stop_act.triggered.connect(self.refresh_video_list)

        self.show()