示例#1
0
def main():
    app = QApplication(
        sys.argv
    )  # must be called in order to be able to use all the stuff below(!)
    print("The application is executed on: %s" % app.platformName())
    l_cameras = QCameraInfo.availableCameras()
    if len(l_cameras) == 0:
        print("ERROR: no cameras found")
        sys.exit(-1)
    else:
        print("INFO: found %i camera(s)" % len(l_cameras))
        print()

    for i_idx, oc_caminfo in enumerate(l_cameras):
        # QCameraInfo - derived properties
        print("Camera #%i:" % i_idx)
        print("\t deviceName: %s" % oc_caminfo.deviceName())
        print("\t description: %s" % oc_caminfo.description())
        print("\t isNull: %s" % oc_caminfo.isNull())
        print("\t orientation: %s" % oc_caminfo.orientation())
        print("\t position: %s" % oc_caminfo.position())

        # QCamera - derived properties
        oc_camera = QCamera(i_idx)
        camera_sync_load_and_start(oc_camera)

        oc_camera_exposure = oc_camera.exposure()
        print("\t captureMode: %s" % captureMode2str(oc_camera.captureMode()))
        print("\t exposure:")
        print("\t\t isAvailabe: %s" % oc_camera_exposure.isAvailable())
        if oc_camera_exposure.isAvailable():
            print("\t\t aperture: %s" % oc_camera_exposure.aperture())
            # TODO test this, add more entries

        oc_camera_focus = oc_camera.focus()
        print("\t focus:")
        print("\t\t isAvailabe: %s" % oc_camera_focus.isAvailable())
        if oc_camera_focus.isAvailable():
            print("\t\t aperture: %f" % oc_camera_focus.digitalZoom())
            # TODO test this, add more entries

        oc_cam_img_proc = oc_camera.imageProcessing()
        print("\t imageProcessing:")
        print("\t\t isAvailabe: %s" % oc_cam_img_proc.isAvailable())
        if oc_cam_img_proc.isAvailable():
            print("\t\t brightness: %f" % oc_cam_img_proc.brightness())
            print("\t\t contrast: %f" % oc_cam_img_proc.contrast())
            print("\t\t denoisingLevel: %f" % oc_cam_img_proc.denoisingLevel())
            print("\t\t manualWhiteBalance: %f" %
                  oc_cam_img_proc.manualWhiteBalance())
            print("\t\t saturation: %f" % oc_cam_img_proc.saturation())
            print("\t\t sharpeningLevel: %f" %
                  oc_cam_img_proc.sharpeningLevel())

        print("\t isVideoCaptureSupported: %s" %
              oc_camera.isCaptureModeSupported(QCamera.CaptureVideo))
        print("\t lockStatus: %s" % lockStatus2str(oc_camera.lockStatus()))
        print("\t requestedLocks: %s" %
              lockType2str(oc_camera.requestedLocks()))
        print("\t state: %s" % state2str(oc_camera.state()))
        print("\t status: %s" % status2str(oc_camera.status()))
        print("\t supportedLocks: %s" %
              lockType2str(oc_camera.supportedLocks()))
        print(
            "\t supportedViewfinderFrameRateRanges: %s" %
            frameRateRange2str(oc_camera.supportedViewfinderFrameRateRanges()))
        print("\t supportedViewfinderPixelFormats: %s" %
              repr(oc_camera.supportedViewfinderPixelFormats()))
        print("\t supportedViewfinderResolutions: \n\t\t%s" %
              frameResolution2str(oc_camera.supportedViewfinderResolutions()))
        print("\t len(supportedViewfinderSettings): %s" %
              len(oc_camera.supportedViewfinderSettings()))

        # QCameraViewfinderSettings - derived properties
        oc_vf_settings = oc_camera.viewfinderSettings()
        if oc_vf_settings.isNull():
            print("\t viewfinderSettings: not supported")
            camera_sync_stop_and_unload(oc_camera)
            print()
            continue
        print("\t maximumFrameRate: %f" % oc_vf_settings.maximumFrameRate())
        print("\t minimumFrameRate: %f" % oc_vf_settings.minimumFrameRate())
        print("\t resolution: %s" %
              frameResolution2str([oc_vf_settings.resolution()]))
        # TODO the rest of methods...
        camera_sync_stop_and_unload(oc_camera)
        print()
示例#2
0
class AvatarWidget(QWizardPage):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setSubTitle(self.tr("<h2>Create Your Avatar</h2>"))

        vlayout = QVBoxLayout(self)

        labelLayout = QHBoxLayout()
        labelImage = QLabel()
        labelImage.setPixmap(QPixmap(":/data/images/preferences-desktop-personal.png"))
        labelImage.setMaximumSize(64, 64)
        labelLayout.addWidget(labelImage)

        label = QLabel(self)
        label.setWordWrap(True)
        label.setText(self.tr("<p>This screen helps you set your <strong>user picture</strong>. You can either choose an image from a \
        file or you can capture an image from your camera. Select an option from the <strong>options</strong> menu.</p>"))
        labelLayout.addWidget(label)
        vlayout.addLayout(labelLayout)

        vlayout.addItem(QSpacerItem(20, 40, QSizePolicy.Preferred, QSizePolicy.Preferred))

        centerLayout = QHBoxLayout()
        centerLayout.addItem(QSpacerItem(40, 20, QSizePolicy.Preferred, QSizePolicy.Preferred))

        groupBox = QGroupBox()
        groupBox.setMaximumWidth(500)
        vlayout2 = QVBoxLayout(groupBox)
        hlayout = QHBoxLayout()

        comboBox = QComboBox()
        comboBox.setMinimumWidth(250)
        comboBox.addItems([self.tr("Options"), self.tr("Choose an image...")])

        #Camera control
        self.cameraInfo = None
        self.camera = None
        self.cameraImageCapture = None
        cameras = QCameraInfo.availableCameras()

        if len(cameras):
            self.cameraInfo = cameras[0]
            comboBox.addItem(self.tr("Camera ") + self.cameraInfo.deviceName())
            self.camera = QCamera(self.cameraInfo)
            self.camera.setCaptureMode(QCamera.CaptureStillImage)
            self.cameraImageCapture = QCameraImageCapture(self.camera)
            self.imageProcessing = self.camera.imageProcessing()
            self.imageProcessing.setWhiteBalanceMode(QCameraImageProcessing.WhiteBalanceSunlight)
            self.imageProcessing.setContrast(1)
            self.imageProcessing.setSaturation(1)
            self.imageProcessing.setSharpeningLevel(1)
            self.imageProcessing.setDenoisingLevel(1)
            #self.imageProcessing.setColorFilter(QCameraImageProcessing.ColorFilterWhiteboard) #FIXME Qt5.5
            self.cameraImageCapture.imageCaptured.connect(self.imageCapture)

        self.buttonCam = QPushButton()
        self.buttonCam.setText(self.tr("Capture"))
        self.buttonCam.setIcon(QIcon(":/data/images/webcamreceive.png"))
        self.buttonCam.setVisible(False)

        self.buttonReplay = QPushButton()
        self.buttonReplay.setText(self.tr("Recapture"))
        self.buttonReplay.setIcon(QIcon(":/data/images/view-refresh.png"))
        self.buttonReplay.setVisible(False)

        hlayout.addWidget(comboBox)
        hlayout.addItem(QSpacerItem(300, 20, QSizePolicy.Preferred, QSizePolicy.Preferred))
        hlayout.addWidget(self.buttonCam)
        hlayout.addWidget(self.buttonReplay)

        vlayout2.addLayout(hlayout)

        hlayout2 = QHBoxLayout()

        hlayout2.addItem(QSpacerItem(40, 20, QSizePolicy.Preferred, QSizePolicy.Preferred))

        self.cameraLabel = QLabel()
        self.cameraLabel.setScaledContents(True)
        self.cameraLabel.setStyleSheet("background-color: black;")
        self.cameraLabel.setMinimumSize(320, 240)
        self.cameraLabel.setMaximumSize(320, 240)

        self.cameraView = QCameraViewfinder()
        self.cameraView.setMaximumSize(320,240)
        self.cameraView.setMinimumSize(320,240)
        self.cameraView.hide()

        hlayout2.addWidget(self.cameraLabel)
        hlayout2.addWidget(self.cameraView)

        hlayout2.addItem(QSpacerItem(40, 20, QSizePolicy.Preferred, QSizePolicy.Preferred))
        vlayout2.addLayout(hlayout2)

        centerLayout.addWidget(groupBox)
        centerLayout.addItem(QSpacerItem(40, 20, QSizePolicy.Preferred, QSizePolicy.Preferred))
        vlayout.addLayout(centerLayout)
        vlayout.addItem(QSpacerItem(20, 40, QSizePolicy.Preferred, QSizePolicy.Preferred))

        comboBox.currentIndexChanged.connect(self.avatarSelect)
        self.buttonCam.clicked.connect(self.buttonCamChanged)
        self.buttonReplay.clicked.connect(self.buttonReplayChanged)

        self.userAvatar = None

    def avatarSelect(self, index):
        if index == 0:
            if self.camera != None:
                self.camera.stop()
            self.buttonReplay.hide()
            self.buttonCam.hide()
            self.cameraView.hide()
            self.cameraLabel.show()
        elif index == 1:
            if self.camera != None:
                self.camera.stop()
            self.userAvatar = None
            self.buttonReplay.hide()
            self.buttonCam.hide()
            self.cameraView.hide()
            self.cameraLabel.show()
            file_url, file_type = QFileDialog.getOpenFileName(self, self.tr("Choose Avatar"), QDir.homePath(), "Image (*.png *.jpg)")
            if file_url != "":
                p = QPixmap(file_url)
                self.cameraLabel.setPixmap(p)
                self.userAvatar = file_url
        elif index == 2:
            self.userAvatar = None
            self.cameraLabel.hide()
            self.cameraView.show()
            self.camera.setViewfinder(self.cameraView)
            self.camera.start()
            self.buttonCam.setVisible(True)
            self.buttonReplay.hide()

    def buttonCamChanged(self):
        self.buttonCam.hide()
        self.buttonReplay.show()
        self.camera.searchAndLock()
        self.cameraImageCapture.capture("/tmp/avatar.png")
        self.camera.unlock()
        self.userAvatar = "/tmp/avatar.png"

    def buttonReplayChanged(self):
        self.userAvatar = None
        self.buttonReplay.hide()
        self.buttonCam.show()
        self.camera.start()
        self.cameraLabel.hide()
        self.cameraView.show()

    def imageCapture(self, id, preview):
        pixmap = QPixmap.fromImage(preview)
        self.camera.stop()
        self.cameraView.hide()
        self.cameraLabel.show()
        self.cameraLabel.setPixmap(pixmap)

    def execute(self):
        if self.userAvatar:
            if os.path.exists(os.path.join(os.environ["HOME"], ".face.icon")):
                os.remove(os.path.join(os.environ["HOME"], ".face.icon"))
            shutil.copy(self.userAvatar, os.path.join(os.environ["HOME"], ".face.icon"))
示例#3
0
class AvatarWidget(QWizardPage):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setSubTitle(self.tr("<h2>Create Your Avatar</h2>"))

        vlayout = QVBoxLayout(self)

        labelLayout = QHBoxLayout()
        labelImage = QLabel()
        labelImage.setPixmap(
            QPixmap(":/data/images/preferences-desktop-personal.png"))
        labelImage.setMaximumSize(64, 64)
        labelLayout.addWidget(labelImage)

        label = QLabel(self)
        label.setWordWrap(True)
        label.setText(
            self.
            tr("<p>This screen helps you set your <strong>user picture</strong>. You can either choose an image from a \
        file or you can capture an image from your camera. Select an option from the <strong>options</strong> menu.</p>"
               ))
        labelLayout.addWidget(label)
        vlayout.addLayout(labelLayout)

        vlayout.addItem(
            QSpacerItem(20, 40, QSizePolicy.Preferred, QSizePolicy.Preferred))

        centerLayout = QHBoxLayout()
        centerLayout.addItem(
            QSpacerItem(40, 20, QSizePolicy.Preferred, QSizePolicy.Preferred))

        groupBox = QGroupBox()
        groupBox.setMaximumWidth(500)
        vlayout2 = QVBoxLayout(groupBox)
        hlayout = QHBoxLayout()

        comboBox = QComboBox()
        comboBox.setMinimumWidth(250)
        comboBox.addItems([self.tr("Options"), self.tr("Choose an image...")])

        #Camera control
        self.cameraInfo = None
        self.camera = None
        self.cameraImageCapture = None
        cameras = QCameraInfo.availableCameras()

        if len(cameras):
            self.cameraInfo = cameras[0]
            comboBox.addItem(self.tr("Camera ") + self.cameraInfo.deviceName())
            self.camera = QCamera(self.cameraInfo)
            self.camera.setCaptureMode(QCamera.CaptureStillImage)
            self.cameraImageCapture = QCameraImageCapture(self.camera)
            self.imageProcessing = self.camera.imageProcessing()
            self.imageProcessing.setWhiteBalanceMode(
                QCameraImageProcessing.WhiteBalanceSunlight)
            self.imageProcessing.setContrast(1)
            self.imageProcessing.setSaturation(1)
            self.imageProcessing.setSharpeningLevel(1)
            self.imageProcessing.setDenoisingLevel(1)
            #self.imageProcessing.setColorFilter(QCameraImageProcessing.ColorFilterWhiteboard) #FIXME Qt5.5
            self.cameraImageCapture.imageCaptured.connect(self.imageCapture)

        self.buttonCam = QPushButton()
        self.buttonCam.setText(self.tr("Capture"))
        self.buttonCam.setIcon(QIcon(":/data/images/webcamreceive.png"))
        self.buttonCam.setVisible(False)

        self.buttonReplay = QPushButton()
        self.buttonReplay.setText(self.tr("Recapture"))
        self.buttonReplay.setIcon(QIcon(":/data/images/view-refresh.png"))
        self.buttonReplay.setVisible(False)

        hlayout.addWidget(comboBox)
        hlayout.addItem(
            QSpacerItem(300, 20, QSizePolicy.Preferred, QSizePolicy.Preferred))
        hlayout.addWidget(self.buttonCam)
        hlayout.addWidget(self.buttonReplay)

        vlayout2.addLayout(hlayout)

        hlayout2 = QHBoxLayout()

        hlayout2.addItem(
            QSpacerItem(40, 20, QSizePolicy.Preferred, QSizePolicy.Preferred))

        self.cameraLabel = QLabel()
        self.cameraLabel.setScaledContents(True)
        self.cameraLabel.setStyleSheet("background-color: black;")
        self.cameraLabel.setMinimumSize(320, 240)
        self.cameraLabel.setMaximumSize(320, 240)

        self.cameraView = QCameraViewfinder()
        self.cameraView.setMaximumSize(320, 240)
        self.cameraView.setMinimumSize(320, 240)
        self.cameraView.hide()

        hlayout2.addWidget(self.cameraLabel)
        hlayout2.addWidget(self.cameraView)

        hlayout2.addItem(
            QSpacerItem(40, 20, QSizePolicy.Preferred, QSizePolicy.Preferred))
        vlayout2.addLayout(hlayout2)

        centerLayout.addWidget(groupBox)
        centerLayout.addItem(
            QSpacerItem(40, 20, QSizePolicy.Preferred, QSizePolicy.Preferred))
        vlayout.addLayout(centerLayout)
        vlayout.addItem(
            QSpacerItem(20, 40, QSizePolicy.Preferred, QSizePolicy.Preferred))

        comboBox.currentIndexChanged.connect(self.avatarSelect)
        self.buttonCam.clicked.connect(self.buttonCamChanged)
        self.buttonReplay.clicked.connect(self.buttonReplayChanged)

        self.userAvatar = None

    def avatarSelect(self, index):
        if index == 0:
            if self.camera != None:
                self.camera.stop()
            self.buttonReplay.hide()
            self.buttonCam.hide()
            self.cameraView.hide()
            self.cameraLabel.show()
        elif index == 1:
            if self.camera != None:
                self.camera.stop()
            self.userAvatar = None
            self.buttonReplay.hide()
            self.buttonCam.hide()
            self.cameraView.hide()
            self.cameraLabel.show()
            file_url, file_type = QFileDialog.getOpenFileName(
                self, self.tr("Choose Avatar"), QDir.homePath(),
                "Image (*.png *.jpg)")
            if file_url != "":
                p = QPixmap(file_url)
                self.cameraLabel.setPixmap(p)
                self.userAvatar = file_url
        elif index == 2:
            self.userAvatar = None
            self.cameraLabel.hide()
            self.cameraView.show()
            self.camera.setViewfinder(self.cameraView)
            self.camera.start()
            self.buttonCam.setVisible(True)
            self.buttonReplay.hide()

    def buttonCamChanged(self):
        self.buttonCam.hide()
        self.buttonReplay.show()
        self.camera.searchAndLock()
        self.cameraImageCapture.capture("/tmp/avatar.png")
        self.camera.unlock()
        self.userAvatar = "/tmp/avatar.png"

    def buttonReplayChanged(self):
        self.userAvatar = None
        self.buttonReplay.hide()
        self.buttonCam.show()
        self.camera.start()
        self.cameraLabel.hide()
        self.cameraView.show()

    def imageCapture(self, id, preview):
        pixmap = QPixmap.fromImage(preview)
        self.camera.stop()
        self.cameraView.hide()
        self.cameraLabel.show()
        self.cameraLabel.setPixmap(pixmap)

    def execute(self):
        if self.userAvatar:
            if os.path.exists(os.path.join(os.environ["HOME"], ".face.icon")):
                os.remove(os.path.join(os.environ["HOME"], ".face.icon"))
            shutil.copy(self.userAvatar,
                        os.path.join(os.environ["HOME"], ".face.icon"))