def __init__(self, parent=None): super(Camera, self).__init__(parent) self.ui = Ui_Camera() self.pre_id = 0 self.cur_id = 0 self.count = 0 self.checked = 0 self.audio_settime = 0 self.allow_flag = 1 self.check_list = [] self.camera = None self.imageCapture = None self.isCapturingImage = False self.applicationExiting = False self.ui.setupUi(self) cameraDevice = QByteArray() videoDevicesGroup = QActionGroup(self) videoDevicesGroup.setExclusive(True) for deviceName in QCamera.availableDevices(): description = QCamera.deviceDescription(deviceName) videoDeviceAction = QAction(description, videoDevicesGroup) videoDeviceAction.setCheckable(True) videoDeviceAction.setData(deviceName) if cameraDevice.isEmpty(): cameraDevice = deviceName videoDeviceAction.setChecked(True) self.ui.menuDevices.addAction(videoDeviceAction) videoDevicesGroup.triggered.connect(self.updateCameraDevice) self.setCamera(cameraDevice) # Create and load model path_pretrained = "apis/models/facenet/20180402-114759.pb" path_SVM = "apis/models/SVM/SVM.pkl" self.recognizer = Recognizer() self.recognizer.create_graph(path_pretrained, path_SVM)
def select_camera(self, i): """Starts the selected camera. If "Choose webcam" is selected, it stops the camera. Parameters ---------- i: Index of the chosen camera. """ self.Label_Bild.image = logo_with_text self.Label_Bild.setPixmap(QPixmap(self.Label_Bild.image)) if i == 0: self.camera.stop() self.detector.disable_detection() self.Button_Detection.setText( QCoreApplication.translate(WINDOW, START)) self.stacked_widget.setCurrentIndex(0) self.camera_viewfinder.hide() self.Label_Bild.show() time.sleep(2) self.Label_Bild.image = logo_with_text self.Label_Bild.setPixmap(QPixmap(self.Label_Bild.image)) self.Label_Bild.setStyleSheet(""" """) else: self.camera_viewfinder.show() self.stacked_widget.setCurrentIndex(1) self.Label_Bild.hide() self.camera = QCamera(self.available_cameras[i - 1]) self.camera.setViewfinder(self.camera_viewfinder) self.camera.error.connect( lambda: self.alert(self.camera.errorString())) self.camera.start() self.Button_Bild.setText(QCoreApplication.translate( WINDOW, ENABLE))
def setupCamera(self, cam_name): """ Create and setup camera functions. """ for camera in self.cameras: # Select camera by matching cam_name to one of the # devices in the cameras list. if camera.deviceName() == cam_name: self.cam = QCamera(camera) # Construct QCamera device # Create camera viewfinder widget and add it to the # view_finder_window. self.view_finder = QCameraViewfinder() self.view_finder_window.setWidget(self.view_finder) self.view_finder.show() # Sets the view finder to display video self.cam.setViewfinder(self.view_finder) # QCameraImageCapture() is used for taking # images or recordings. self.image_capture = QCameraImageCapture(self.cam) # Configure the camera to capture still images. self.cam.setCaptureMode(QCamera.CaptureStillImage) self.cam.start() # Slot to start the camera else: pass
def setCamera(self, cameraDevice): if cameraDevice.isEmpty(): self.camera = QCamera() else: self.camera = QCamera(cameraDevice) self.captureAction.setEnabled(True)
def __init__(self): QMainWindow.__init__(self) if len(QCameraInfo.availableCameras()) == 0: QMessageBox.warning( self, 'Camera not found', 'You don\'t have any cameras on your computer so you can\'t use this app...\nBuy a new camera (╯°^°)╯┻━┻', QMessageBox.Ok) exit(-1) self.central_widget = QWidget(self) self.main_grid = QGridLayout(self.central_widget) self.option_group = QGroupBox(None) self.group_grid = QGridLayout(self.option_group) self.addr_msg = QLabel('Database addr') self.camera_msg = QLabel('Camera') self.camera_combo = QComboBox() self.addr_edit = QLineEdit() self.camera_place = QGroupBox(None) self.auth_btn = QPushButton('Log in') self.camera_grid = QGridLayout(self.camera_place) self.camera_widget = QCameraViewfinder() self.camera_obj = QCamera(QCameraInfo.defaultCamera()) self.veg_cfg = Config()
def setCamera(self, cameraDevice): if cameraDevice.isEmpty(): self.camera = QCamera() else: self.camera = QCamera(cameraDevice) self.camera.setViewfinder(self.viewfinder) self.camera.start()
def __init__(self, *args, camera_info=None): super(CameraInterface, self).__init__(*args) # 定义相机实例对象并设置捕获模式 if camera_info: self.mCamera = QCamera(camera_info) else: self.mCamera = QCamera() self.mCamera.setCaptureMode(QCamera.CaptureViewfinder) self.mDisplayWidth = 800 self.mDisplayHeight = 600 self.mRate = 10 # 设置取景器分辨率 self.setDisplaySize(self.mDisplayWidth, self.mDisplayHeight) self.setRate(self.mRate) # 初始化取景器 self.mViewCamera = QtMultimediaWidgets.QCameraViewfinder(self) self.mViewCamera.show() self.mCamera.setViewfinder(self.mViewCamera) self.mCamera.setCaptureMode(QCamera.CaptureStillImage) # 设置图像捕获 self.mCapture = QCameraImageCapture(self.mCamera) if self.mCapture.isCaptureDestinationSupported( QCameraImageCapture.CaptureToBuffer): self.mCapture.setCaptureDestination( QCameraImageCapture.CaptureToBuffer) # CaptureToBuffer # self.mCapture.error.connect(lambda i, e, s: self.alert(s)) self.mCapture.imageAvailable.connect(self.readFrame) self.mTimerImageGrab = QTimer(self) self.mTimerImageGrab.timeout.connect(self.timerImgGrab)
def load_cam(self): self.cam_page.setLayout(self.cam_page_lay) self.error_cam.hide() self.camera = QCameraInfo.defaultCamera() # Проверяем, что камера сущетсвует # Если нет, то переключаемся на вторую вкладку if self.camera.isNull(): dialog = QErrorMessage() dialog.setWindowTitle('Warning') dialog.showMessage( 'Not enough cameras, the app will only be available in drawing mode' ) dialog.exec() self.error_cam.show() self.cam_page.setEnabled(False) self.tabWidget.setCurrentIndex(1) # Если да, то на первую else: self.tabWidget.setCurrentIndex(0) self.camera = QCamera(self.camera) self.view_cam = QCameraViewfinder(self) self.view_cam.setMediaObject(self.camera) self.view_cam.setAutoFillBackground(True) self.camera.setViewfinder(self.view_cam) self.box_lay = QVBoxLayout(self) self.box_lay.addWidget(self.view_cam) self.scrolling.setLayout(self.box_lay) # Запускаем камеру self.camera.start() # Подвязываем кнопку к слоту со снимком self.bt_cam.clicked.connect(self.make_ph) # Можно зумить фотографию self.zoom.valueChanged.connect(self.zoom_pict)
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))
def __iniCamera(self): ##创建 QCamera对象 camInfo = QCameraInfo.defaultCamera() #获取缺省摄像头,QCameraInfo self.ui.comboCamera.addItem(camInfo.description()) #摄像头描述 self.ui.comboCamera.setCurrentIndex(0) self.camera = QCamera(camInfo) #创建摄像头对象 self.camera.setViewfinder(self.ui.viewFinder) #设置取景框预览 ## camera.setCaptureMode(QCamera.CaptureViewfinder) #预览 self.camera.setCaptureMode(QCamera.CaptureStillImage) #设置为抓图 ## camera.setCaptureMode(QCamera.CaptureVideo) mode = QCamera.CaptureStillImage supported = self.camera.isCaptureModeSupported(mode) self.ui.checkStillImage.setChecked(supported) #支持拍照 supported = self.camera.isCaptureModeSupported(QCamera.CaptureVideo) self.ui.checkVideo.setChecked(supported) #支持视频录制 supported = self.camera.exposure().isAvailable() self.ui.checkExposure.setChecked(supported) #支持曝光补偿 supported = self.camera.focus().isAvailable() self.ui.checkFocus.setChecked(supported) #支持变焦 self.camera.stateChanged.connect(self.do_cameraStateChanged)
def showCamera(self): self.finder = QCameraViewfinder() self.finder.show() self.camera = QCamera() self.camera.setViewfinder(self.finder) self.camera.start() self.camera.stop()
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)
def __init__(self, parent=None, standalone=False): super(Camera, self).__init__(parent) # This prevents doing unneeded initialization # when QtDesginer loads the plugin. if parent is None and not standalone: return if not multimedia_available: return self.ui = uic.loadUi(os.path.join(WIDGET_PATH, "camera.ui"), self) self.camera = None self.imageCapture = None self.mediaRecorder = None self.isCapturingImage = False self.applicationExiting = False self.imageSettings = QImageEncoderSettings() self.audioSettings = QAudioEncoderSettings() self.videoSettings = QVideoEncoderSettings() self.videoContainerFormat = '' camera_device = QByteArray() videoDevicesGroup = QActionGroup(self) videoDevicesGroup.setExclusive(True) if not QCamera.availableDevices(): self.ui.devicesCombo.addItem("No Device") else: for deviceName in QCamera.availableDevices(): description = QCamera.deviceDescription(deviceName) self.ui.devicesCombo.addItem(description) videoDeviceAction = QAction(description, videoDevicesGroup) videoDeviceAction.setCheckable(True) videoDeviceAction.setData(deviceName) if camera_device.isEmpty(): cameraDevice = deviceName videoDeviceAction.setChecked(True) self.ui.devicesCombo.addAction(videoDeviceAction) videoDevicesGroup.triggered.connect(self.updateCameraDevice) self.ui.captureWidget.currentChanged.connect(self.updateCaptureMode) self.ui.devicesCombo.currentIndexChanged.connect( self.get_device_action) self.ui.lockButton.hide() # Start camera 2s after the UI has loaded QTimer.singleShot(2000, lambda: self.setCamera(camera_device))
def __initCamera(self): camInfo = QCameraInfo.defaultCamera() self.camera = QCamera(camInfo) self.camera2 = QCamera(camInfo) self.camera.setViewfinder(self._ui.widget) self.camera2.setViewfinder(self._ui.widget_2) self.camera.setCaptureMode( QCamera.CaptureStillImage) #captureviewfinder self.camera2.setCaptureMode(QCamera.CaptureStillImage)
def __init__(self): super(self.__class__, self).__init__() self.setupUi(self) # gets defined in the UI file # th = CamThread(self) # th.changePixmap.connect(self.setImagae) # th.start() self.cam = QCamera() self.cam.setViewfinder(self.widget) self.cam.start()
def start_preview(self, i_cam_idx): if self.oc_camera is not None: self.oc_camera.stop() del self.oc_camera self.oc_camera = QCamera(self.l_cameras[i_cam_idx]) self.oc_camera.setViewfinder(self.oc_viewfinder) self.oc_camera.setCaptureMode(QCamera.CaptureVideo) self.oc_camera.error.connect(lambda: self.show_error(self.oc_camera.errorString())) self.oc_camera.start()
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)
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)
def __init__(self,parent = None): super(QCameraImageCapture, self).__init__(None,parent) self.camera = QCamera() self.camera.setCaptureMode(QCamera.CaptureStillImage); self.setMediaObject(self.camera) # self.setCaptureDestination(QCameraImageCapture.CaptureToFile) self.imageSaved.connect(self._captureComplete) self.imageCaptured.connect(self._imageCaptured)
def __init__(self): super(MainWindow, self).__init__() self.cameraInfo = QCameraInfo.defaultCamera() self.camera = QCamera(self.cameraInfo) self.camera.setCaptureMode(QCamera.CaptureStillImage) self.imageCapture = QCameraImageCapture(self.camera) self.imageCapture.imageCaptured.connect(self.imageCaptured) self.imageCapture.imageSaved.connect(self.imageSaved) self.currentPreview = QImage() toolBar = QToolBar() self.addToolBar(toolBar) fileMenu = self.menuBar().addMenu("&File") shutterIcon = QIcon("/Users/thethelafaltein/PycharmProjects/ResNetApplication/res/img/shutter.svg") self.takePictureAction = QAction(shutterIcon, "&Take Picture", self, shortcut="Ctrl+T", triggered=self.takePicture) self.takePictureAction.setToolTip("Take Picture") fileMenu.addAction(self.takePictureAction) toolBar.addAction(self.takePictureAction) exitAction = QAction(QIcon.fromTheme("application-exit"), "E&xit", self, shortcut="Ctrl+Q", triggered=self.close) fileMenu.addAction(exitAction) aboutMenu = self.menuBar().addMenu("&About") aboutQtAction = QAction("About &Qt", self, triggered=qApp.aboutQt) aboutMenu.addAction(aboutQtAction) self.tabWidget = QTabWidget() self.setCentralWidget(self.tabWidget) self.cameraViewfinder = QCameraViewfinder() self.camera.setViewfinder(self.cameraViewfinder) self.tabWidget.addTab(self.cameraViewfinder, "Viewfinder") if self.camera.status() != QCamera.UnavailableStatus: name = self.cameraInfo.description() self.setWindowTitle("PySide2 Camera Example (" + name + ")") self.statusBar().showMessage("Starting: '" + name + "'", 5000) self.camera.start() else: self.setWindowTitle("Object classifier") self.takePictureAction.setEnabled(False) self.statusBar().showMessage("Camera unavailable", 5000)
def setup_opencv_camera(self): if len(QCamera.availableDevices()) > 0: camera_addr = str(QCamera.availableDevices()[0]) self.camera = cv2.VideoCapture(0) if self.camera.isOpened(): self.camera.set(cv2.CAP_PROP_BUFFERSIZE, 1) self.camera.set(cv2.CAP_PROP_FRAME_WIDTH, 640) self.camera.set(cv2.CAP_PROP_FRAME_HEIGHT, 480) logger.info('Opened the camera {}'.format(camera_addr)) else: logger.error( 'Failed to open the camera {}'.format(camera_addr))
def iniCamera(self): cameras = QCameraInfo.availableCameras() for cameraInfo in cameras: # select the capturing device if it is available if (cameraInfo.description().find("Capture") is not -1): self.cam = QCamera(cameraInfo) self.caminfo = QCameraInfo(self.cam) self.recorder = QMediaRecorder(self.cam) print("Camera Chosen: " + self.caminfo.description()) print(self.cam.supportedViewfinderFrameRateRanges()) if self.cam.isCaptureModeSupported(QCamera.CaptureVideo): print("Capturemode supported")
class Camera(QObject): 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) def iniCamera(self): cameras = QCameraInfo.availableCameras() for cameraInfo in cameras: # select the capturing device if it is available if (cameraInfo.description().find("Capture") is not -1): self.cam = QCamera(cameraInfo) self.caminfo = QCameraInfo(self.cam) self.recorder = QMediaRecorder(self.cam) print("Camera Chosen: " + self.caminfo.description()) print(self.cam.supportedViewfinderFrameRateRanges()) if self.cam.isCaptureModeSupported(QCamera.CaptureVideo): print("Capturemode supported") def startVid(self): self.cam.load() # self.camvfind.show() self.cam.setViewfinder(self.camvfind) self.cam.setCaptureMode(QCamera.CaptureVideo) self.cam.start() audio = QAudioEncoderSettings() audio.setCodec("audio/amr") audio.setQuality(QtMultimedia.QMultimedia.NormalQuality) video = QVideoEncoderSettings() # video.setCodec("video/mp4") video.setQuality(QtMultimedia.QMultimedia.NormalQuality) video.setResolution(1920, 1080) video.setFrameRate(30.0) # self.recorder.setAudioSettings(audio) self.recorder.setVideoSettings(video) self.recorder.setContainerFormat("mp4") def startRecording(self, filename): directory = os.path.abspath(str(os.getcwd())) abs_path = os.path.join(directory, filename) self.recorder.setOutputLocation(QUrl(abs_path)) self.recorder.record() def stopRecording(self): self.recorder.stop() def getViewFinder(self): return self.camvfind
def __init__(self, parent=None): super(VideoWindow, self).__init__(parent) self.setWindowTitle( "PyQt Video Player Widget Example - pythonprogramminglanguage.com") self.mediaPlayer = QMediaPlayer(None, QMediaPlayer.VideoSurface) self.camera = QCamera(0) self.cameraviewfinder = QCameraViewfinder() self.cameramode = self.camera.CaptureMode(2) self.cameraimgcap = QCameraImageCapture(self.camera) videoWidget = QVideoWidget() self.imageView = QLabel("add a image file") self.imageView.setAlignment(Qt.AlignCenter) self.playButton = QPushButton() self.playButton.setEnabled(True) self.playButton.setIcon(self.style().standardIcon(QStyle.SP_MediaPlay)) self.playButton.clicked.connect(self.play) self.positionSlider = QSlider(Qt.Horizontal) self.positionSlider.setRange(0, 0) self.scene1 = QGraphicsScene() self.view1 = QGraphicsView(self.scene1) # Create new action # Create exit action # Create a widget for window contents wid = QWidget(self) self.setCentralWidget(wid) # Create layouts to place inside widget # controlLayout = QHBoxLayout() # controlLayout.setContentsMargins(0, 0, 0, 0) # controlLayout.addWidget(self.playButton) # controlLayout.addWidget(self.positionSlider) videolayout = QVBoxLayout() videolayout.addWidget(videoWidget) # videolayout.addLayout(controlLayout) # Set widget to contain window contents layout = QHBoxLayout() layout.addLayout(videolayout) layout.addWidget(self.cameraviewfinder) # layout.addWidget(self.view1) wid.setLayout(layout) self.mediaPlayer.setVideoOutput(videoWidget) self.cameraviewfinder.show() self.camera.setViewfinder(self.cameraviewfinder)
def __fetch_cam(self): for device_obj in QCamera.availableDevices(): cam_name = QCamera.deviceDescription(device_obj) cam = QCamera(device_obj) self.cams[str(cam_name)] = cam cam_image_capture = QCameraImageCapture(cam) cam_image_capture.setEncodingSettings(QImageEncoderSettings()) cam_image_capture.captureDestination() cam_image_capture.imageSaved.connect(self.on_image_saved) self.__cam_image_captures[str(cam_name)] = cam_image_capture cam.statusChanged.connect(self.set_resolution)
def start(self, dev=1): if self.camera: self.camera.stop() cameras = QCameraInfo.availableCameras() self.camera = QCamera(cameras[dev]) self.camera.setViewfinder(self.viewfinder) self.camera.setCaptureMode(QCamera.CaptureStillImage) self.camera.start() self.camera_capture = QCameraImageCapture(self.camera) self.camera_capture.setCaptureDestination( QCameraImageCapture.CaptureToBuffer) self.camera_capture.imageCaptured.connect(self.imageCaptured)
def __init__(self, parent=None): super(Camera, self).__init__(parent) global API API = AlgorithmAPIs(template_dir="templates", threshold=0.5, use_multiprocessing=False) self.ui = Ui_Camera() self.camera = None self.imageCapture = None # self.mediaRecorder = None self.isCapturingImage = False self.applicationExiting = False self.imageSettings = QImageEncoderSettings() self.audioSettings = QAudioEncoderSettings() self.ui.setupUi(self) cameraDevice = QByteArray() videoDevicesGroup = QActionGroup(self) videoDevicesGroup.setExclusive(True) for deviceName in QCamera.availableDevices(): description = QCamera.deviceDescription(deviceName) videoDeviceAction = QAction(description, videoDevicesGroup) videoDeviceAction.setCheckable(True) videoDeviceAction.setData(deviceName) if cameraDevice.isEmpty(): cameraDevice = deviceName videoDeviceAction.setChecked(True) self.ui.menuDevices.addAction(videoDeviceAction) videoDevicesGroup.triggered.connect(self.updateCameraDevice) self.ui.lcdNumber_2.display(0) self.ui.dial.valueChanged.connect(self.dial_display) global dial_value dial_value = 3 self.ui.lcdNumber_2.display(dial_value) self.setCamera(cameraDevice) # Create and load model path_pretrained = "apis/models/facenet/20180402-114759.pb" path_SVM = "apis/models/SVM/SVM.pkl" self.recognizer = Recognizer() self.recognizer.create_graph(path_pretrained, path_SVM)
def start_ui(self): self.zui = Ui_zwin() self.zui.setupUi(self) self.zui.camera_label.setScaledContents(True) # 初始化信息 self.zui.label_xuehao.setText("工号:") self.zui.label_mingzi.setText("姓名:") self.zui.label_time.setText("签到时间:") # 查询按钮 self.zui.cxbtn.clicked.connect(self.cx_ui) # 注册按钮 self.zui.zcbtn.clicked.connect(self.zq_zc) # 签到按钮 self.zui.qdbtn.clicked.connect(self.zq_qd) # 删除按钮 self.zui.del_btn.clicked.connect(self.del_yg) # 导出按钮 self.zui.out_btn.clicked.connect(self.out_ex) # 摄像头控制 camera = QCamera(self) # 创建摄像头 cameraviewfinder = QCameraViewfinder(self.zui.camera_label) # 创建显示窗口 cameraviewfinder.resize(752, 420) self.cameraImageCapture = QCameraImageCapture(camera) # 绑定获取的摄像头 self.cameraImageCapture.setCaptureDestination( QCameraImageCapture.CaptureToFile) # 获取数据类型 camera.setCaptureMode(QCamera.CaptureStillImage) camera.setViewfinder(cameraviewfinder) # 绑定窗口 camera.start() # 开启摄像头
class Camera(QObject): 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) def iniCamera(self): print(self.caminfo.description()) print(self.caminfo.availableCameras()) for caminfo in QCameraInfo.availableCameras(): print(caminfo.deviceName()) if self.cam.isCaptureModeSupported(self.cammode): print("Capturemode supported") def startVid(self): #self.camimgcap.CaptureDestination(2) self.camvfind.show() self.cam.setViewfinder(self.camvfind) self.cam.setCaptureMode(self.cammode) self.cam.start()
def start_scan(self, device: str = ''): """ Scans a QR code from the given camera device. If no QR code is found the returned string will be empty. If the camera is not found or can't be opened NoCamerasFound will be raised. """ self.validator = QrReaderValidatorCounted() self.validator.strong_count = 5 # FIXME: make this time based rather than framect based device_info = None for camera in QCameraInfo.availableCameras(): if camera.deviceName() == device: device_info = camera break if not device_info: self.logger.info( 'Failed to open selected camera, trying to use default camera') device_info = QCameraInfo.defaultCamera() if not device_info or device_info.isNull(): raise NoCamerasFound( _("Cannot start QR scanner, no usable camera found.") + self._linux_pyqt5bug_msg()) self._init_stats() self.qrreader_res = [] self.validator_res = None self._ok_done = False self._error_message = None if self.camera: self.logger.info( "Warning: start_scan already called for this instance.") self.camera = QCamera(device_info) self.camera.setViewfinder(self.video_surface) self.camera.setCaptureMode(QCamera.CaptureViewfinder) # this operates on camera from within the signal handler, so should be a queued connection self.camera_sc_conn = self.camera.statusChanged.connect( self._on_camera_status_changed, Qt.QueuedConnection) self.camera.error.connect( self._on_camera_error ) # log the errors we get, if any, for debugging # Camera needs to be loaded to query resolutions, this tries to open the camera self.camera.load()
def __init__(self, parent=None): super(Camera, self).__init__(parent) self.ui = Ui_Camera() self.camera = None self.imageCapture = None self.mediaRecorder = None self.isCapturingImage = False self.applicationExiting = False self.imageSettings = QImageEncoderSettings() self.audioSettings = QAudioEncoderSettings() self.videoSettings = QVideoEncoderSettings() self.videoContainerFormat = '' self.ui.setupUi(self) cameraDevice = QByteArray() videoDevicesGroup = QActionGroup(self) videoDevicesGroup.setExclusive(True) #for multiple cameras ata for deviceName in QCamera.availableDevices(): description = QCamera.deviceDescription(deviceName) videoDeviceAction = QAction(description, videoDevicesGroup) videoDeviceAction.setCheckable(True) videoDeviceAction.setData(deviceName) if cameraDevice.isEmpty(): cameraDevice = deviceName videoDeviceAction.setChecked(True) self.ui.menuDevices.addAction(videoDeviceAction) videoDevicesGroup.triggered.connect(self.updateCameraDevice) self.ui.captureWidget.currentChanged.connect(self.updateCaptureMode) self.ui.lockButton.hide() self.setCamera(cameraDevice)
def setCamera(self, cameraDevice): if cameraDevice.isEmpty(): self.camera = QCamera() else: self.camera = QCamera(cameraDevice) self.camera.stateChanged.connect(self.updateCameraState) self.camera.error.connect(self.displayCameraError) self.mediaRecorder = QMediaRecorder(self.camera) self.mediaRecorder.stateChanged.connect(self.updateRecorderState) self.imageCapture = QCameraImageCapture(self.camera) self.mediaRecorder.durationChanged.connect(self.updateRecordTime) self.mediaRecorder.error.connect(self.displayRecorderError) self.mediaRecorder.setMetaData(QMediaMetaData.Title, "Test Title") self.ui.exposureCompensation.valueChanged.connect( self.setExposureCompensation) self.camera.setViewfinder(self.ui.viewfinder) self.updateCameraState(self.camera.state()) self.updateLockStatus(self.camera.lockStatus(), QCamera.UserRequest) self.updateRecorderState(self.mediaRecorder.state()) self.imageCapture.readyForCaptureChanged.connect(self.readyForCapture) self.imageCapture.imageCaptured.connect(self.processCapturedImage) self.imageCapture.imageSaved.connect(self.imageSaved) self.camera.lockStatusChanged.connect(self.updateLockStatus) self.ui.captureWidget.setTabEnabled(0, self.camera.isCaptureModeSupported(QCamera.CaptureStillImage)) self.ui.captureWidget.setTabEnabled(1, self.camera.isCaptureModeSupported(QCamera.CaptureVideo)) self.updateCaptureMode() self.camera.start() self.show()
class CameraWidget(QWidget): def __init__(self, background_color): QWidget.__init__(self) self.scene = QGraphicsScene(self) self.scene.setBackgroundBrush(QBrush(background_color)) self.graphics_view = QGraphicsView(self.scene) self.graphics_view.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.graphics_view.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.graphics_view.setFrameStyle(0) self.graphics_view.setStyleSheet("QGraphicsView {background: transparent; border: 3px; outline: none;}") self.graphics_view.scale(-1, 1) # this make live video from camero mirror. self.video_item = QGraphicsVideoItem() self.scene.addItem(self.video_item) self.layout = QVBoxLayout(self) self.layout.setContentsMargins(0, 0, 0, 0) self.layout.addWidget(self.graphics_view) self.available_cameras = QCameraInfo.availableCameras() # Set the default camera. self.select_camera(0) def resizeEvent(self, event): self.video_item.setSize(QSizeF(event.size().width(), event.size().height())) QWidget.resizeEvent(self, event) def select_camera(self, i): self.camera = QCamera(self.available_cameras[i]) self.camera.setViewfinder(self.video_item) self.camera.setCaptureMode(QCamera.CaptureStillImage) self.camera.start()
class Camera(QMainWindow): def __init__(self, parent=None): super(Camera, self).__init__(parent) self.ui = Ui_Camera() self.camera = None self.imageCapture = None self.mediaRecorder = None self.isCapturingImage = False self.applicationExiting = False self.imageSettings = QImageEncoderSettings() self.audioSettings = QAudioEncoderSettings() self.videoSettings = QVideoEncoderSettings() self.videoContainerFormat = '' self.ui.setupUi(self) cameraDevice = QByteArray() videoDevicesGroup = QActionGroup(self) videoDevicesGroup.setExclusive(True) for deviceName in QCamera.availableDevices(): description = QCamera.deviceDescription(deviceName) videoDeviceAction = QAction(description, videoDevicesGroup) videoDeviceAction.setCheckable(True) videoDeviceAction.setData(deviceName) if cameraDevice.isEmpty(): cameraDevice = deviceName videoDeviceAction.setChecked(True) self.ui.menuDevices.addAction(videoDeviceAction) videoDevicesGroup.triggered.connect(self.updateCameraDevice) self.ui.captureWidget.currentChanged.connect(self.updateCaptureMode) self.ui.lockButton.hide() self.setCamera(cameraDevice) def setCamera(self, cameraDevice): if cameraDevice.isEmpty(): self.camera = QCamera() else: self.camera = QCamera(cameraDevice) self.camera.stateChanged.connect(self.updateCameraState) self.camera.error.connect(self.displayCameraError) self.mediaRecorder = QMediaRecorder(self.camera) self.mediaRecorder.stateChanged.connect(self.updateRecorderState) self.imageCapture = QCameraImageCapture(self.camera) self.mediaRecorder.durationChanged.connect(self.updateRecordTime) self.mediaRecorder.error.connect(self.displayRecorderError) self.mediaRecorder.setMetaData(QMediaMetaData.Title, "Test Title") self.ui.exposureCompensation.valueChanged.connect( self.setExposureCompensation) self.camera.setViewfinder(self.ui.viewfinder) self.updateCameraState(self.camera.state()) self.updateLockStatus(self.camera.lockStatus(), QCamera.UserRequest) self.updateRecorderState(self.mediaRecorder.state()) self.imageCapture.readyForCaptureChanged.connect(self.readyForCapture) self.imageCapture.imageCaptured.connect(self.processCapturedImage) self.imageCapture.imageSaved.connect(self.imageSaved) self.camera.lockStatusChanged.connect(self.updateLockStatus) self.ui.captureWidget.setTabEnabled(0, self.camera.isCaptureModeSupported(QCamera.CaptureStillImage)) self.ui.captureWidget.setTabEnabled(1, self.camera.isCaptureModeSupported(QCamera.CaptureVideo)) self.updateCaptureMode() self.camera.start() def keyPressEvent(self, event): if event.isAutoRepeat(): return if event.key() == Qt.Key_CameraFocus: self.displayViewfinder() self.camera.searchAndLock() event.accept() elif event.key() == Qt.Key_Camera: if self.camera.captureMode() == QCamera.CaptureStillImage: self.takeImage() elif self.mediaRecorder.state() == QMediaRecorder.RecordingState: self.stop() else: self.record() event.accept() else: super(Camera, self).keyPressEvent(event) def keyReleaseEvent(self, event): if event.isAutoRepeat(): return if event.key() == Qt.Key_CameraFocus: self.camera.unlock() else: super(Camera, self).keyReleaseEvent(event) def updateRecordTime(self): msg = "Recorded %d sec" % self.mediaRecorder.duration() // 1000 self.ui.statusbar.showMessage(msg) def processCapturedImage(self, requestId, img): scaledImage = img.scaled(self.ui.viewfinder.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation) self.ui.lastImagePreviewLabel.setPixmap(QPixmap.fromImage(scaledImage)) self.displayCapturedImage() QTimer.singleShot(4000, self.displayViewfinder) def configureCaptureSettings(self): if self.camera.captureMode() == QCamera.CaptureStillImage: self.configureImageSettings() elif self.camera.captureMode() == QCamera.CaptureVideo: self.configureVideoSettings() def configureVideoSettings(self): settingsDialog = VideoSettings(self.mediaRecorder) settingsDialog.setAudioSettings(self.audioSettings) settingsDialog.setVideoSettings(self.videoSettings) settingsDialog.setFormat(self.videoContainerFormat) if settingsDialog.exec_(): self.audioSettings = settingsDialog.audioSettings() self.videoSettings = settingsDialog.videoSettings() self.videoContainerFormat = settingsDialog.format() self.mediaRecorder.setEncodingSettings(self.audioSettings, self.videoSettings, self.videoContainerFormat) def configureImageSettings(self): settingsDialog = ImageSettings(self.imageCapture) settingsDialog.setImageSettings(self.imageSettings) if settingsDialog.exec_(): self.imageSettings = settingsDialog.imageSettings() imageCapture.setEncodingSettings(self.imageSettings) def record(self): self.mediaRecorder.record() self.updateRecordTime() def pause(self): self.mediaRecorder.pause() def stop(self): self.mediaRecorder.stop() def setMuted(self, muted): self.mediaRecorder.setMuted(muted) def toggleLock(self): if self.camera.lockStatus() in (QCamera.Searching, QCamera.Locked): self.camera.unlock() elif self.camera.lockStatus() == QCamera.Unlocked: self.camera.searchAndLock() def updateLockStatus(self, status, reason): indicationColor = Qt.black if status == QCamera.Searching: self.ui.statusbar.showMessage("Focusing...") self.ui.lockButton.setText("Focusing...") indicationColor = Qt.yellow elif status == QCamera.Locked: self.ui.lockButton.setText("Unlock") self.ui.statusbar.showMessage("Focused", 2000) indicationColor = Qt.darkGreen elif status == QCamera.Unlocked: self.ui.lockButton.setText("Focus") if reason == QCamera.LockFailed: self.ui.statusbar.showMessage("Focus Failed", 2000) indicationColor = Qt.red palette = self.ui.lockButton.palette() palette.setColor(QPalette.ButtonText, indicationColor) self.ui.lockButton.setPalette(palette) def takeImage(self): self.isCapturingImage = True self.imageCapture.capture() def startCamera(self): self.camera.start() def stopCamera(self): self.camera.stop() def updateCaptureMode(self): tabIndex = self.ui.captureWidget.currentIndex() captureMode = QCamera.CaptureStillImage if tabIndex == 0 else QCamera.CaptureVideo if self.camera.isCaptureModeSupported(captureMode): self.camera.setCaptureMode(captureMode) def updateCameraState(self, state): if state == QCamera.ActiveState: self.ui.actionStartCamera.setEnabled(False) self.ui.actionStopCamera.setEnabled(True) self.ui.captureWidget.setEnabled(True) self.ui.actionSettings.setEnabled(True) elif state in (QCamera.UnloadedState, QCamera.LoadedState): self.ui.actionStartCamera.setEnabled(True) self.ui.actionStopCamera.setEnabled(False) self.ui.captureWidget.setEnabled(False) self.ui.actionSettings.setEnabled(False) def updateRecorderState(self, state): if state == QMediaRecorder.StoppedState: self.ui.recordButton.setEnabled(True) self.ui.pauseButton.setEnabled(True) self.ui.stopButton.setEnabled(False) elif state == QMediaRecorder.PausedState: self.ui.recordButton.setEnabled(True) self.ui.pauseButton.setEnabled(False) self.ui.stopButton.setEnabled(True) elif state == QMediaRecorder.RecordingState: self.ui.recordButton.setEnabled(False) self.ui.pauseButton.setEnabled(True) self.ui.stopButton.setEnabled(True) def setExposureCompensation(self, index): self.camera.exposure().setExposureCompensation(index * 0.5) def displayRecorderError(self): QMessageBox.warning(self, "Capture error", self.mediaRecorder.errorString()) def displayCameraError(self): QMessageBox.warning(self, "Camera error", self.camera.errorString()) def updateCameraDevice(self, action): self.setCamera(action.data()) def displayViewfinder(self): self.ui.stackedWidget.setCurrentIndex(0) def displayCapturedImage(self): self.ui.stackedWidget.setCurrentIndex(1) def readyForCapture(self, ready): self.ui.takeImageButton.setEnabled(ready) def imageSaved(self, id, fileName): self.isCapturingImage = False if self.applicationExiting: self.close() def closeEvent(self, event): if self.isCapturingImage: self.setEnabled(False) self.applicationExiting = True event.ignore() else: event.accept()
def select_camera(self, i): self.camera = QCamera(self.available_cameras[i]) self.camera.setViewfinder(self.video_item) self.camera.setCaptureMode(QCamera.CaptureStillImage) self.camera.start()
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"))
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