Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. List available camera resolutions
Forum Updated to NodeBB v4.3 + New Features

List available camera resolutions

Scheduled Pinned Locked Moved Unsolved Qt for Python
3 Posts 3 Posters 428 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    Xav12358
    wrote on last edited by
    #1

    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) ### Empty
    

    Can someone help me ?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Based on the documentation you are doing two things wrong:

      • it's an object and not a class method
      • you are not ensuring that the camera is in the Loaded state as required.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • Volodymyr14V Offline
        Volodymyr14V Offline
        Volodymyr14
        wrote on last edited by Volodymyr14
        #3

        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_()) 
        

        PyQt/PySide

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved