List available camera resolutions
-
Hello,
I try to find on python a solution to get all available resolutions on my camera
I find many example but nothing work. I use Pyside2 on python 3.6 on Ubuntu 18.04.Here is the code I tried:
from PySide2 import QtCore from PySide2 import QtGui from PySide2.QtWidgets import QApplication, QMainWindow from PySide2.QtCore import * from PySide2 import QtWidgets, QtMultimedia .... cameras = QtMultimedia.QCamera.availableDevices() for camera in cameras: print(" -- camera {0}".format(camera)) i = QtMultimedia.QCamera(camera) j = QtMultimedia.QCameraImageCapture(i) resolution_list = QtMultimedia.QCamera.supportedViewfinderResolutions(i) ### EmptyCan someone help me ?
-
Try this:
import os from PySide2 import QtMultimedia, QtMultimediaWidgets from PySide2 import QtWidgets, QtCore, QtGui class UMedia(QtMultimediaWidgets.QCameraViewfinder): def __init__(self, parent=None): super(UMedia, self).__init__(parent) self.setWindowTitle("U Camera") self.setWindowOpacity(0.95) self.camera = QtMultimedia.QCamera() self.camera.setViewfinder(self) self.camera.start() self.cambut1 = QtWidgets.QPushButton(self) self.cambut1.setText("Capture") self.cambut1.setVisible(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) def img_capture(self): image_capture = QtMultimedia.QCameraImageCapture(self.camera) image_capture.setCaptureDestination( QtMultimedia.QCameraImageCapture.CaptureToFile) self.camera.setCaptureMode(QtMultimedia.QCamera.CaptureStillImage) filename = os.path.dirname(os.path.abspath(__file__)) camera_path = os.path.join(filename, "camera/captures/") image_capture.capture(os.path.normpath(camera_path)) def enterEvent(self, event): self.cambut1.setVisible(True) def leaveEvent(self, event): self.cambut1.setVisible(False) if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) uap_vc = UMedia() uap_vc.show() sys.exit(app.exec_())