Example #1
0
    def __init__(self):
        super().__init__()
        self.setLayout(qtw.QVBoxLayout())

        # camera
        self.camera = qtmm.QCamera()

        # viewfinder
        cvf = qtmmw.QCameraViewfinder()
        self.camera.setViewfinder(cvf)
        self.layout().addWidget(cvf)

        # Form
        form = qtw.QFormLayout()
        self.layout().addLayout(form)

        # zoom
        zoomslider = qtw.QSlider(minimum=1,
                                 maximum=10,
                                 sliderMoved=self.on_slider_moved,
                                 orientation=qtc.Qt.Horizontal)
        form.addRow('Zoom', zoomslider)

        self.camera.start()
        self.show()
Example #2
0
    def selectCamera(self, index):
        pre_index = self.index(self.available_cameras, self.selected_camera)
        if pre_index is index:
            if self.camera.state() == QtMultimedia.QCamera.LoadedState:
                self.camera.start()
            return
        if pre_index is not None:
            self.releaseCamera()
            for imageObject in self.images:
                if "pixmap" not in imageObject:
                    print(
                        "detected unfulfilled capture while switching camera, removing..."
                    )
                    self.images.remove(imageObject)
        self.captureButton.setDisabled(True)
        self.selected_camera = self.available_cameras[index]
        self.camera = QtMultimedia.QCamera(self.selected_camera)
        self.camera.setViewfinder(self.viewfinder)
        self.camera.setCaptureMode(QtMultimedia.QCamera.CaptureStillImage)
        self.camera.statusChanged.connect(
            lambda status: self.enableCaptureButton() if status == QtMultimedia
            .QCamera.ActiveStatus and len(self.images) < 12 else None)
        self.camera.error.connect(
            lambda: self.alert("camera error", self.camera.errorString()))
        self.camera.start()

        self.capture = QtMultimedia.QCameraImageCapture(self.camera)
        self.capture.error.connect(
            lambda i, e, s: self.alert("capture error", s))
        self.capture.imageCaptured.connect(self.imageCaptured)
Example #3
0
 def get_webcam(self, i):
     self.my_webcam = QtMultimedia.QCamera(self.online_webcams[i])
     self.my_webcam.setViewfinder(self.exist)
     self.my_webcam.setCaptureMode(QtMultimedia.QCamera.CaptureStillImage)
     self.my_webcam.error.connect(
         lambda: self.alert(self.my_webcam.errorString()))
     self.my_webcam.start()
Example #4
0
    def __init__(self, parent=None):
        super(MainWindow, self).__init__()

        # window settings
        self.setWindowTitle("QRScanner App")

        # main layout
        self.lay = QtWidgets.QVBoxLayout()

        # widgets
        self.capture_button = QtWidgets.QPushButton("Capture")
        self.capture_button.clicked.connect(self.btn_click)
        self.label = QtWidgets.QLabel("")

        # setting the device
        self.device = QtMultimedia.QCamera.availableDevices()[0]
        self.m_camera = QtMultimedia.QCamera(self.device)

        #test
        self.label.setText(str(self.m_camera.availableDevices()))

        self.view_finder = QtMultimediaWidgets.QCameraViewfinder()
        self.view_finder.setMinimumSize(250, 250)

        self.m_camera.setViewfinder(self.view_finder)
        self.m_camera.setCaptureMode(QtMultimedia.QCamera.CaptureStillImage)
        self.m_camera.start()

        self.lay.addWidget(self.label)
        self.lay.addWidget(self.view_finder)
        self.lay.addWidget(self.capture_button)
        self.lay.addWidget(self.label)
        self.setLayout(self.lay)
 def camera_check(self):
     cameras = qtmm.QCameraInfo.availableCameras()
     print(cameras)
     if not cameras:
         qtw.QMessageBox.critical(
             self, 'No cameras',
             'No cameras were found, recording disabled.')
     else:
         return qtmm.QCamera(cameras[0])
def get_cameras():
    """
    Get all cameras connecting to the host machine.

    :return: all available cameras using "Camera" Class's instance
    """
    cameras_info = QtMultimedia.QCameraInfo.availableCameras()
    cameras = [Camera(QtMultimedia.QCamera(item)) for item in cameras_info]
    return cameras
 def __init__(self, parent=None):  # Constructor of the class.
     super(UMedia, self).__init__(parent)  # Initialization of the class.
     self.setWindowTitle("U Camera")  # Title of the application.
     win_icon = QtGui.QIcon("Icons/python1.png")
     self.setWindowIcon(win_icon)  # Set icon for this window.
     self.setWindowOpacity(0.95)  # Set widget opacity.
     self.camera = QtMultimedia.QCamera()  # Video Camera device.
     self.camera.setViewfinder(self)  # Set viewfinder for this
     self.camera.start()  # camera and start.
     self.cambut1 = UBut1(self, pad=10)  # Button for capture image.
     self.cambut1.setText("Capture")  # Text of the button.
     self.cambut1.setVisible(False)  # Set button visible false.
     self.cambut1.clicked.connect(self.img_capture)
     self.vc_grid = QtWidgets.QGridLayout()
     self.vc_grid.addWidget(self.cambut1, 0, 0, 1, 1)
     self.vc_grid.setAlignment(QtCore.Qt.AlignTop)
     self.setLayout(self.vc_grid)  # Sets layout to the widget.
Example #8
0
 def activate_camera(self):
     cameras = QtMultimedia.QCameraInfo.availableCameras()
     for caminfo in cameras:
         self.camera = QtMultimedia.QCamera(caminfo)
         self.camera.setCaptureMode(QtMultimedia.QCamera.CaptureViewfinder)
         break
     if self.camera:
         self.camera.setViewfinder(self.viewfinder)
     self.camera.load()
     sizes = self.camera.supportedViewfinderResolutions()
     if sizes:
         size = sizes[-1]
         if size.height() and size.width():
             self.aspect = float(size.width()) / size.height()
         else:
             self.aspect = 1.333333333
     else:
         self.aspect = 1.333333333
     self.viewfinder.setFixedWidth(self.camera_width)
     self.viewfinder.setFixedHeight(self.camera_width / self.aspect)
Example #9
0
    def captureToggle(self):
        tabs = self.mainWindow.previewTabs
        if tabs.currentWidget() != self.mainWindow.cameraTab:
            tabs.setCurrentWidget(self.mainWindow.waitTab)

            try:
                if self.camera is None:
                    if self.cameraInfo is None:
                        self._showError('No camera selected!')
                        tabs.setCurrentWidget(self.mainWindow.badgePreviewTab)
                        return

                    self.camera = QtMultimedia.QCamera(self.cameraInfo)
                    self.camera.viewfinderSettings().setResolution(640, 480)
                    self.camera.setViewfinder(self.mainWindow.cameraViewFinder)

                    def statusChanged(status):
                        if status == QtMultimedia.QCamera.ActiveStatus:
                            tabs.setCurrentWidget(self.mainWindow.cameraTab)

                    self.camera.statusChanged.connect(statusChanged)

                QtCore.QTimer.singleShot(1, self.camera.start)

            except Exception as exc:
                print(exc)
                self._showError('Failed to initialize camera. :(')
                tabs.setCurrentWidget(self.mainWindow.badgePreviewTab)
                return

        elif tabs.currentWidget() == self.mainWindow.cameraTab:

            def imageSaved(id, filename):
                self.useImage(filename)

            self.imageCapture = QtMultimedia.QCameraImageCapture(self.camera)
            self.imageCapture.imageSaved.connect(imageSaved)
            tmpFile = os.path.abspath(os.path.join('archive', '_capture.jpg'))
            self.imageCapture.capture(tmpFile)
            self.camera.stop()
Example #10
0
    def __init__(self, camera_info, output_path, parent=None):
        super(MainWindow, self).__init__(parent)

        # Setup main window
        uifile = StringIO(
            pkgutil.get_data('webrec',
                             'resources/mainwindow.ui').decode('utf-8'))
        uic.loadUi(uifile, self)
        self.output_path = output_path

        # Display the camera image on viewfinder
        camera = QtMultimedia.QCamera(camera_info)
        camera.setCaptureMode(QtMultimedia.QCamera.CaptureVideo)
        self.viewfinder.setCamera(camera)
        self.viewfinder.setRecordDirectory(output_path)

        # Initialize the recorder and connect the signals
        self.recorder = Recorder(parent=self)
        self.recorder.setCamera(camera)

        # Connect the signals
        self.viewfinder.recordStarted.connect(self.recorder.startRecording)
        self.viewfinder.recordStopped.connect(self.recorder.stopRecording)