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 __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 __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()
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 __init__(self, name, default_position='float', parent=None, folded=False): """ All of the panel constructors follow the same format so that the construction can be automated. :param name: Title of the panel and the key for accessing it :param default_position: 'bottom', 'right'... :param parent: self.main """ Panel.__init__(self, name, default_position, parent, folded) self.camera = None self.aspect = 1.333333333 self.camera_width = 320 layout = QtWidgets.QVBoxLayout() widget = QtWidgets.QWidget() layout.setContentsMargins(0, 0, 0, 0) layout.setSizeConstraint(QtWidgets.QLayout.SetFixedSize) self.viewfinder = QtMultimediaWidgets.QCameraViewfinder() layout.addWidget(self.viewfinder) widget.setLayout(layout) self.activate_camera() self.setWidget(widget) self.finish_init() self.releaseMouse()
def __init__(self, camera): super().__init__() self._camera = camera self._camera_viewfinder = QtMultimediaWidgets.QCameraViewfinder() self._camera.setCaptureMode(QtMultimedia.QCamera.CaptureStillImage) self._image_capture = QtMultimedia.QCameraImageCapture(self._camera) self._image_capture.setCaptureDestination( QtMultimedia.QCameraImageCapture.CaptureToFile) self._tag = None self._standard_img = None self._current_frame = None self._current_image_name = None
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.online_webcams = QtMultimedia.QCameraInfo.availableCameras() if not self.online_webcams: pass #quit self.exist = QtMultimediaWidgets.QCameraViewfinder() self.exist.show() self.setCentralWidget(self.exist) # set the default webcam. self.get_webcam(0) self.setWindowTitle("WebCam") self.show()
def start(self): OutDebugInfo("start") diag = QDialog(self) diag.setWindowTitle("Camera") # main layout diag.lay = QtWidgets.QVBoxLayout() # widgets diag.capture_button = QtWidgets.QPushButton("Capture") diag.capture_button.clicked.connect(self.capture_img) diag.label = QtWidgets.QLabel("") # setting the device diag.device = QCamera.availableDevices()[0] diag.m_camera = QCamera(diag.device) diag.view_finder = QtMultimediaWidgets.QCameraViewfinder() diag.view_finder.setMinimumSize(250, 250) diag.m_camera.setViewfinder(diag.view_finder) diag.m_camera.setCaptureMode(QCamera.CaptureStillImage) try: diag.m_camera.start() self.startcamera = True except: pass diag.lay.addWidget(diag.label) diag.lay.addWidget(diag.view_finder) diag.lay.addWidget(diag.capture_button) diag.lay.addWidget(diag.label) diag.setLayout(diag.lay) diag.cp = QCameraImageCapture(diag.m_camera) diag.cp.imageCaptured.connect(self.capture_img_handler) diag.cp.imageSaved.connect(self.save_img) self.capture_diag = diag diag.show() diag.exec_()
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
def __init__(self): super(XrecogCaptureWindow, self).__init__() uic.loadUi(translatePath("capture.ui"), self) self.images = [] self.imageSlots = [] self.selected_camera = None self.camera = None self.capture = None self.hasInit = False slots = [ self.imageGrid.findChildren( QtWidgets.QWidget, QtCore.QRegExp("imageSlot%02d" % index))[0] for index in range(1, 13) ] for slot in slots: newSizePolicy = slot.sizePolicy() newSizePolicy.setRetainSizeWhenHidden(True) slot.setSizePolicy(newSizePolicy) slot.setAttribute(QtCore.Qt.WA_Hover) slot.installEventFilter(self) slot.hide() imageSlot = slot.findChild(QtWidgets.QLabel) imageToolbar = slot.findChildren( QtWidgets.QHBoxLayout, QtCore.QRegExp("imageSlotToolBar\d{2}"))[0] previewButton = slot.findChildren( QtWidgets.QToolButton, QtCore.QRegExp("viewImageButton\d{2}"))[0] deleteButton = slot.findChildren( QtWidgets.QToolButton, QtCore.QRegExp("deleteButton\d{2}"))[0] previewButton.hide() deleteButton.hide() slotObject = {"object": slot, "item": None} previewButton.clicked.connect(self.newPreviewHandler(slotObject)) deleteButton.clicked.connect(self.newDeleteHandler(slotObject)) self.imageSlots.append(slotObject) self.imagepreviewer = XrecogImagePreviewDialog(self) self.viewfinder = QtMultimediaWidgets.QCameraViewfinder() self.viewFinderFrame.layout().addWidget(self.viewfinder) self.installEventFilter(self)
# -*- coding: utf-8 -*- """ Spyder Editor This is a temporary script file. """ from PyQt5.QtMultimedia import QCamera, QCameraImageCapture from PyQt5 import QtMultimediaWidgets cm = QCamera() viewfinder = QtMultimediaWidgets.QCameraViewfinder() viewfinder.show() cm.setViewfinder(viewfinder) cp = QCameraImageCapture(cm) cm.setCaptureMode(cm.CaptureStillImage) cm.start() cm.searchAndLock() cp.capture() cm.unlock()
def __init__(self): """MainWindow constructor. Code in this method should define window properties, create backend resources, etc. """ super().__init__() # Main framework self.resize(qtc.QSize(800, 600)) 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) # transport controls toolbar = self.addToolBar("Transport") record_act = toolbar.addAction('Rec') stop_act = toolbar.addAction('Stop') play_act = toolbar.addAction('Play') pause_act = toolbar.addAction('Pause') # define the video directory 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') # Read the files in the directory self.refresh_video_list() ############ # Playback # ############ # setup the player and video widget self.player = qtmm.QMediaPlayer() self.video_widget = qtmmw.QVideoWidget() self.player.setVideoOutput(self.video_widget) notebook.addTab(self.video_widget, "Play") # connect the transport 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)) # connect file list self.file_list.itemDoubleClicked.connect( self.on_file_selected) self.file_list.itemDoubleClicked.connect( lambda: notebook.setCurrentWidget(self.video_widget)) ############# # Recording # ############# # set up camera self.camera = self.camera_check() if not self.camera: self.show() return self.camera.setCaptureMode(qtmm.QCamera.CaptureVideo) # Create the viewfinder widget for recording self.cvf = qtmmw.QCameraViewfinder() self.camera.setViewfinder(self.cvf) notebook.addTab(self.cvf, 'Record') # start the camera self.camera.start() # Configure recorder 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) # connect the transport 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) # refresh the files when the recording is made stop_act.triggered.connect(self.refresh_video_list) self.show()