Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Capture system camera frames from thread
Forum Updated to NodeBB v4.3 + New Features

Capture system camera frames from thread

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 414 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.
  • FalsinSoftF Offline
    FalsinSoftF Offline
    FalsinSoft
    wrote on last edited by
    #1

    Hi all

    I need to capture frames from a system camera using a separate thread. Follow my code from a derived QThread class:

    void CameraMonitor::run()
    {
    	QScopedPointer<QCamera> camera(new QCamera(cameraDevice));
        QScopedPointer<QMediaCaptureSession> captureSession(new QMediaCaptureSession());
        QScopedPointer<QVideoSink> videoSink(new QVideoSink());
    
        camera->setFocusMode(QCamera::FocusModeAuto);
    
        connect(videoSink.data(), &QVideoSink::videoFrameChanged, this, &CameraMonitor::processVideoFrame);
        captureSession->setVideoSink(videoSink.data());
        captureSession->setCamera(camera.data());
        camera->start();
    
        exec();
    
        camera->stop();
        captureSession->setCamera(nullptr);
        captureSession->setVideoSink(nullptr);
    }
    
    void CameraMonitor::processVideoFrame(const QVideoFrame &videoFrame)
    {
        //....
    }
    

    My problem is that the processVideoFrame slot is nevel called and I don't understand if I made some mystake in the code or simply this is not the correct way to get the result. I can see the camera led on that's mean the code activate the camera but I don't understand if it doesn't acquire or the signal/slot sistem doesn't work also calling exec() inside the thread.
    Someone can help me?
    Thank you

    Ronel_qtmasterR 1 Reply Last reply
    0
    • FalsinSoftF FalsinSoft

      Hi all

      I need to capture frames from a system camera using a separate thread. Follow my code from a derived QThread class:

      void CameraMonitor::run()
      {
      	QScopedPointer<QCamera> camera(new QCamera(cameraDevice));
          QScopedPointer<QMediaCaptureSession> captureSession(new QMediaCaptureSession());
          QScopedPointer<QVideoSink> videoSink(new QVideoSink());
      
          camera->setFocusMode(QCamera::FocusModeAuto);
      
          connect(videoSink.data(), &QVideoSink::videoFrameChanged, this, &CameraMonitor::processVideoFrame);
          captureSession->setVideoSink(videoSink.data());
          captureSession->setCamera(camera.data());
          camera->start();
      
          exec();
      
          camera->stop();
          captureSession->setCamera(nullptr);
          captureSession->setVideoSink(nullptr);
      }
      
      void CameraMonitor::processVideoFrame(const QVideoFrame &videoFrame)
      {
          //....
      }
      

      My problem is that the processVideoFrame slot is nevel called and I don't understand if I made some mystake in the code or simply this is not the correct way to get the result. I can see the camera led on that's mean the code activate the camera but I don't understand if it doesn't acquire or the signal/slot sistem doesn't work also calling exec() inside the thread.
      Someone can help me?
      Thank you

      Ronel_qtmasterR Offline
      Ronel_qtmasterR Offline
      Ronel_qtmaster
      wrote on last edited by
      #2

      @FalsinSoft first of all
      void QCamera::setViewfinder(QAbstractVideoSurface *surface)

      You have to create an abstract video surface and add it to the camera using the function setViewfinder.

      Then, the video surface will notify you when a frame is present
      Finally, call your thread class when the frame is present and give it as an argument the image(QVideoFrame converted to QImage)

      FalsinSoftF 1 Reply Last reply
      0
      • Ronel_qtmasterR Ronel_qtmaster

        @FalsinSoft first of all
        void QCamera::setViewfinder(QAbstractVideoSurface *surface)

        You have to create an abstract video surface and add it to the camera using the function setViewfinder.

        Then, the video surface will notify you when a frame is present
        Finally, call your thread class when the frame is present and give it as an argument the image(QVideoFrame converted to QImage)

        FalsinSoftF Offline
        FalsinSoftF Offline
        FalsinSoft
        wrote on last edited by
        #3

        @Ronel_qtmaster Thank you for your reply but I'm developing using Qt6 and there is no method setViewfinder in the "new" QCamera class...

        Ronel_qtmasterR 2 Replies Last reply
        0
        • FalsinSoftF FalsinSoft

          @Ronel_qtmaster Thank you for your reply but I'm developing using Qt6 and there is no method setViewfinder in the "new" QCamera class...

          Ronel_qtmasterR Offline
          Ronel_qtmasterR Offline
          Ronel_qtmaster
          wrote on last edited by
          #4
          This post is deleted!
          1 Reply Last reply
          0
          • FalsinSoftF FalsinSoft

            @Ronel_qtmaster Thank you for your reply but I'm developing using Qt6 and there is no method setViewfinder in the "new" QCamera class...

            Ronel_qtmasterR Offline
            Ronel_qtmasterR Offline
            Ronel_qtmaster
            wrote on last edited by
            #5

            @FalsinSoft SORRY I AM not using qt6

            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