Exemple #1
0
 def __init__(self):
     super(CameraMainWin, self).__init__()
     self.setupUi(self)
     #定义相机实例对象并设置捕获模式
     self.camera = QCamera()
     self.camera.setCaptureMode(QCamera.CaptureViewfinder)
     self.cameraOpened = False  # 设置相机打开状态为未打开
     #设置取景器分辨率
     viewFinderSettings = QCameraViewfinderSettings()
     viewFinderSettings.setResolution(800, 600)
     self.camera.setViewfinderSettings(viewFinderSettings)
     #初始化取景器
     self.viewCamera = QtMultimediaWidgets.QCameraViewfinder(self)
     self.camera.setViewfinder(self.viewCamera)
     self.camera.setCaptureMode(QCamera.CaptureStillImage)
     self.camerLayout.addWidget(self.viewCamera)  #取景器放置到预留的布局中
     #设置图像捕获
     self.capture = QCameraImageCapture(self.camera)
     self.capture.setCaptureDestination(
         QCameraImageCapture.CaptureToBuffer)  #CaptureToBuffer
     self.switchCamera: QPushButton
     self.switchCamera.clicked.connect(self.SwitchCamera)
     self.takePic.clicked.connect(self.TakePic)
     self.capture.error.connect(lambda i, e, s: self.alert(s))
     self.capture.imageAvailable.connect(self.saveImage)
     self.capture.imageCaptured.connect(
         lambda d, i: self.status.showMessage("Image %04d captured" % self.
                                              save_seq))
Exemple #2
0
 def setDisplaySize(self, display_width_: int, display_height_: int):
     self.mDisplayWidth = display_width_
     self.mDisplayHeight = display_height_
     viewFinderSettings = QCameraViewfinderSettings()
     viewFinderSettings.setResolution(self.mDisplayWidth,
                                      self.mDisplayHeight)
     self.mCamera.setViewfinderSettings(viewFinderSettings)
Exemple #3
0
    def _on_camera_status_changed(self, status: QCamera.Status):
        if self._ok_done:
            # camera/scan is quitting, abort.
            return

        self.print_error('camera status changed to {}'.format(self._get_camera_status_name(status)))

        if status == QCamera.LoadedStatus:
            # Determine the optimal resolution and compute the crop rect
            camera_resolutions = self.camera.supportedViewfinderResolutions()
            try:
                resolution, was_ideal = self._get_resolution(camera_resolutions, self.SCAN_SIZE)
            except RuntimeError as e:
                self._error_message = str(e)
                self.reject()
                return
            self._set_resolution(resolution)

            # Set the camera resolution
            viewfinder_settings = QCameraViewfinderSettings()
            viewfinder_settings.setResolution(resolution)
            self.camera.setViewfinderSettings(viewfinder_settings)

            # Counter for the QR scanner frame number
            self.frame_id = 0

            self.camera.start()
            self.lowres_label.setVisible(not was_ideal)  # if they have a low res camera, show the warning label.
        elif status == QCamera.UnloadedStatus or status == QCamera.UnavailableStatus:
            self._error_message = _("Cannot start QR scanner, camera is unavailable.")
            self.reject()
        elif status == QCamera.ActiveStatus:
            self.open()
Exemple #4
0
    def _on_status_changed(self, status: QCamera.Status) -> None:
        logger.debug("_on_camera_status_changed: %s", status)
        if status == QCamera.LoadedStatus:
            supported_resolutions = self.supportedViewfinderResolutions()
            logger.info("Supported view finder resolutions: %s",
                        supported_resolutions)
            if self._requested_viewfinder_resolution:
                if self._requested_viewfinder_resolution in supported_resolutions:
                    logger.info(
                        "Setting resolution to %s",
                        self._requested_viewfinder_resolution,
                    )
                    requested_settings = QCameraViewfinderSettings()
                    requested_settings.setResolution(
                        self._requested_viewfinder_resolution)
                    self.setViewfinderSettings(requested_settings)
                else:
                    raise ValueError(
                        "Requested viewfinder resolution %s, "
                        "but the only supported resolutions are %s",
                        ", ".join(map(str, supported_resolutions)),
                    )

            camera_resolution = self.viewfinderSettings().resolution()
            logger.info("Using resolution: %s", camera_resolution)
Exemple #5
0
 def __init__(self, parent=QObject()):
     super(Camera, self).__init__(parent)
     # chooses the system default camera
     self.cam = QCamera()
     self.caminfo = QCameraInfo(self.cam)
     self.camvfind = QCameraViewfinder()
     self.camvfindset = QCameraViewfinderSettings()
     self.recorder = QMediaRecorder(self.cam)
Exemple #6
0
 def __init__(self, parent = QObject()):
     super(Camera, self).__init__(parent)
     print("3")
     self.cam = QCamera(QCameraInfo.defaultCamera())   #"/dev/video0".encode()
     print("4")
     self.caminfo = QCameraInfo(self.cam)
     self.camvfind = QCameraViewfinder()
     self.camvfindset = QCameraViewfinderSettings()
     self.cammode = self.cam.CaptureMode(0)
     self.camimgcap = QCameraImageCapture(self.cam)
Exemple #7
0
    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)
Exemple #8
0
    def openCamera(self):
        if not self.mCameraOpened:
            self.mCamera.start()

            viewFinderSettings = QCameraViewfinderSettings()
            rate_range = self.mCamera.supportedViewfinderFrameRateRanges()
            if rate_range:
                viewFinderSettings.setMinimumFrameRate(
                    rate_range[0].minimumFrameRate)
                viewFinderSettings.setMaximumFrameRate(
                    rate_range[0].maximumFrameRate)
            else:
                viewFinderSettings.setMinimumFrameRate(1)
                viewFinderSettings.setMaximumFrameRate(self.mRate)
            self.mTimerImageGrab.start(1000 / self.mRate)
            self.mCameraOpened = True
 def __init__(self):
     super(CameraMainWin, self).__init__()
     self.setupUi(self)
     #定义相机实例对象并设置捕获模式
     self.camera = QCamera()
     self.camera.setCaptureMode(QCamera.CaptureViewfinder)
     self.cameraOpened = False  # 设置相机打开状态为未打开
     #设置取景器分辨率
     viewFinderSettings = QCameraViewfinderSettings()
     viewFinderSettings.setResolution(800, 600)
     self.camera.setViewfinderSettings(viewFinderSettings)
     #初始化取景器
     self.viewCamera = QtMultimediaWidgets.QCameraViewfinder(self)
     self.camera.setViewfinder(self.viewCamera)
     self.camerLayout.addWidget(self.viewCamera)  #取景器放置到预留的布局中
     #设置图像捕获
     self.capImg = QCameraImageCapture(self.camera)
     self.capImg.setCaptureDestination(
         QCameraImageCapture.CaptureToFile)  #CaptureToBuffer
Exemple #10
0
from PyQt5.QtMultimedia import QCamera, QCameraViewfinderSettings

camera = QCamera()
viewfinder = QCameraViewfinderSettings()
camera.setViewfinder(viewfinder)
viewfinder.show()

camera.start()