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. Qt 6.2: QImageCapture is not ready - what is wrong?

Qt 6.2: QImageCapture is not ready - what is wrong?

Scheduled Pinned Locked Moved Solved Qt for Python
3 Posts 2 Posters 875 Views 1 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.
  • S Offline
    S Offline
    StarterKit
    wrote on last edited by StarterKit
    #1

    Hi,
    I have a code that captures images from camera and it works well with Qt 5 (PySide2). Now I port it to Qt 6.2 and faced some problems with image capture. Reducing it to minimal reproducible example I've found that my QImageCapture object never says it is ready for capture. Manual says that call of capture() method should fail when readyForCapture() is False but in reality it works and doesn't raise an error.
    So either I do something wrong or there is a bug in Qt 6.2. You may find my code below. When I press the button I always have:

    PySide6.QtCore.QSize(1280, 720)
    Is capture ready: False
    

    But if I call capture() after it - image is available (I haven't included it into example to reduce code size). The question is - are there any error in my code that keeps QImageCapture in "not ready" state?
    My code is below:

    from PySide6.QtWidgets import QMainWindow, QWidget, QVBoxLayout, QPushButton
    from PySide6.QtMultimedia import QCamera, QMediaCaptureSession, QImageCapture
    from PySide6.QtMultimediaWidgets import QVideoWidget
    
    class CameraWnd(QMainWindow):
        def __init__(self):
            QMainWindow.__init__(self)
            self.layout = QVBoxLayout()
    
            self.viewfinder = QVideoWidget(self)
            self.layout.addWidget(self.viewfinder)
            self.viewfinder.setMinimumSize(720, 405)
    
            self.button = QPushButton(self)
            self.button.setText("Check state")
            self.layout.addWidget(self.button)
    
            self.wnd = QWidget(self)
            self.wnd.setLayout(self.layout)
            self.setCentralWidget(self.wnd)
    
            self.camera = QCamera()
            self.captureSession = QMediaCaptureSession()
            self.img_capture = QImageCapture(self.camera)
    
            self.captureSession.setCamera(self.camera)
            self.captureSession.setVideoOutput(self.viewfinder)
            self.captureSession.setImageCapture(self.img_capture)
    
            self.button.clicked.connect(self.on_button)
            self.img_capture.errorOccurred.connect(self.on_error)
            self.camera.errorOccurred.connect(self.on_cam_error)
    
        def on_button(self):
            print(self.viewfinder.videoSink().videoSize())
            print(f"Is capture ready: {self.img_capture.isReadyForCapture()}")
    
        def on_error(self, _id, _error, error_str):
            print(f"Error: {error_str}")
    
        def on_cam_error(self, _error, error_str):
            print(f"Error: {error_str}")
    
    jsulmJ 1 Reply Last reply
    0
    • S StarterKit

      Hi,
      I have a code that captures images from camera and it works well with Qt 5 (PySide2). Now I port it to Qt 6.2 and faced some problems with image capture. Reducing it to minimal reproducible example I've found that my QImageCapture object never says it is ready for capture. Manual says that call of capture() method should fail when readyForCapture() is False but in reality it works and doesn't raise an error.
      So either I do something wrong or there is a bug in Qt 6.2. You may find my code below. When I press the button I always have:

      PySide6.QtCore.QSize(1280, 720)
      Is capture ready: False
      

      But if I call capture() after it - image is available (I haven't included it into example to reduce code size). The question is - are there any error in my code that keeps QImageCapture in "not ready" state?
      My code is below:

      from PySide6.QtWidgets import QMainWindow, QWidget, QVBoxLayout, QPushButton
      from PySide6.QtMultimedia import QCamera, QMediaCaptureSession, QImageCapture
      from PySide6.QtMultimediaWidgets import QVideoWidget
      
      class CameraWnd(QMainWindow):
          def __init__(self):
              QMainWindow.__init__(self)
              self.layout = QVBoxLayout()
      
              self.viewfinder = QVideoWidget(self)
              self.layout.addWidget(self.viewfinder)
              self.viewfinder.setMinimumSize(720, 405)
      
              self.button = QPushButton(self)
              self.button.setText("Check state")
              self.layout.addWidget(self.button)
      
              self.wnd = QWidget(self)
              self.wnd.setLayout(self.layout)
              self.setCentralWidget(self.wnd)
      
              self.camera = QCamera()
              self.captureSession = QMediaCaptureSession()
              self.img_capture = QImageCapture(self.camera)
      
              self.captureSession.setCamera(self.camera)
              self.captureSession.setVideoOutput(self.viewfinder)
              self.captureSession.setImageCapture(self.img_capture)
      
              self.button.clicked.connect(self.on_button)
              self.img_capture.errorOccurred.connect(self.on_error)
              self.camera.errorOccurred.connect(self.on_cam_error)
      
          def on_button(self):
              print(self.viewfinder.videoSink().videoSize())
              print(f"Is capture ready: {self.img_capture.isReadyForCapture()}")
      
          def on_error(self, _id, _error, error_str):
              print(f"Error: {error_str}")
      
          def on_cam_error(self, _error, error_str):
              print(f"Error: {error_str}")
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @StarterKit Did you start the camera?

      camera->start();
      camera->searchAndLock();
      

      https://doc.qt.io/qt-5/qcameraimagecapture.html

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      S 1 Reply Last reply
      1
      • jsulmJ jsulm

        @StarterKit Did you start the camera?

        camera->start();
        camera->searchAndLock();
        

        https://doc.qt.io/qt-5/qcameraimagecapture.html

        S Offline
        S Offline
        StarterKit
        wrote on last edited by StarterKit
        #3

        @jsulm Bingo!
        I occasionally removed self.camera.start() from my code and haven't noticed it until your reply. Thanks a lot, that was the reason (Funny thing - everything worked and looked normally in this small example except object returned "not Ready" always)

        But the way, there are no searchAndLock() for QCamera in 6.2 anymore (that is one of my troubles and my old code was linked to it...)

        1 Reply Last reply
        0

        • Login

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