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. Help capturing an image
Forum Updated to NodeBB v4.3 + New Features

Help capturing an image

Scheduled Pinned Locked Moved Unsolved General and Desktop
27 Posts 4 Posters 2.6k 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.
  • J Offline
    J Offline
    John1123
    wrote on last edited by
    #1

    Hello,
    I'm using multimedia to try and capture an image from my camera. I believe my connections are correct (they're similar to the example that is provided) but whenever I try to capture() a readyForCaptureChanged signal is emitted and isReadyForCapture changes from true to false. I made this a few months ago, I forgot which version I was on, and it was working fine, but recently I updated the components and I'm unable to capture an image.

    1 Reply Last reply
    0
    • Axel SpoerlA Offline
      Axel SpoerlA Offline
      Axel Spoerl
      Moderators
      wrote on last edited by
      #2

      Since there is no code posted, we don't know what you are actually trying.
      Maybe just read this, and if it doesn't solve your problem - post your code.

      Software Engineer
      The Qt Company, Oslo

      1 Reply Last reply
      0
      • J Offline
        J Offline
        John1123
        wrote on last edited by
        #3

        Thanks for getting back to me, unfortunately the link that you sent didn't help me. Here's the code that I'm using

        from another file I'm calling getAvailableDevices(), then initDevice with a valid device index, then I'm setting the settings in captureSetting, and lastly I call captureFrame() where the image is supposed to be captured. The problem though is that whenever capture() is called readyForCapture is called again but ready is set to false.

        VideoCapture::VideoCapture(QImage *image)
        {
        savedImage = image;
        }

        void VideoCapture::getAvailableDevices()
        {
        m_devices = QMediaDevices::videoInputs();
        }

        void VideoCapture::initDevice(const int deviceIdx )
        {
        int cnt = 0;

        for (const QCameraDevice &cameraDevice : m_devices)
        {
            qDebug() << cnt << ". " << cameraDevice.description();
        
            if(cameraDevice.isNull())
            {
                qDebug() << "\t"<< cnt++ << " is null\n";
            }
        }
        qDebug() << "Initializing device " << deviceIdx << " for capturing an image" << Qt::endl;
        
        /*Initialize a capture device*/
        m_targetDevice.reset(new QCamera(m_devices[deviceIdx]));
        m_captureSession.setCamera(m_targetDevice.data());
        
        /*Initialize a QImageCapture instance*/
        m_capture = new QImageCapture;
        m_captureSession.setImageCapture(m_capture);
        
        /*Connections for updating the camera*/
        connect(m_targetDevice.data(), &QCamera::activeChanged, this, &VideoCapture::updateCameraActive, Qt::DirectConnection);
        connect(m_targetDevice.data(), &QCamera::errorOccurred, this, &VideoCapture::cameraError, Qt::DirectConnection);
        
        /*Conenctions for capturing an image*/
        connect(m_capture, &QImageCapture::readyForCaptureChanged, this, &VideoCapture::readyForCapture, Qt::DirectConnection);
        connect(m_capture, &QImageCapture::imageCaptured, this, &VideoCapture::imageCaptured, Qt::DirectConnection);
        connect(m_capture, &QImageCapture::errorOccurred, this, &VideoCapture::captureError, Qt::DirectConnection);
        

        };

        void VideoCapture::updateCameraActive(bool ready)
        {
        if (ready)
        {
        qDebug() << "Camera is active ";
        }
        else
        {
        qDebug() << "Camera is not active";
        }
        }

        void VideoCapture::captureSetting(int width, int height)
        {
        m_capture->setFileFormat(QImageCapture::PNG);
        m_capture->setQuality(QImageCapture::VeryHighQuality);
        m_capture->setResolution(width, height);
        }

        void VideoCapture::captureFrame()
        {
        m_targetDevice->start();
        updateCameraActive(m_targetDevice->isActive());
        checkReadyForCapture();
        readyForCapture(m_capture->isReadyForCapture());
        }

        void VideoCapture::imageCaptured(int requestId, const QImage &img)
        {
        Q_UNUSED(requestId);
        Q_UNUSED(img);
        qDebug() << "Image Captured!!";
        *savedImage = img.copy();
        m_targetDevice->stop();
        }

        void VideoCapture::readyForCapture(bool ready)
        {
        if(ready)
        {
        qDebug() << "Capture ready";
        m_capture->capture();
        }
        else
        {
        qDebug() << "Capture not ready";
        }
        }

        void VideoCapture::captureError(int id, const QImageCapture::Error error, const QString &errorString)
        {
        Q_UNUSED(id);
        Q_UNUSED(error);
        qDebug() << "Capture Error: " << errorString;
        m_targetDevice->stop();
        }

        void VideoCapture::cameraError()
        {
        if (m_targetDevice->error() != QCamera::NoError)
        {
        qDebug() << "Camera error: " << m_targetDevice->errorString();
        }
        }

        void VideoCapture::checkReadyForCapture()
        {
        QString boolStr = m_capture->isReadyForCapture() ? "True" : "False";
        qDebug() << "isReadyForCapture: " << boolStr;
        }

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

          Hi,

          There several strange (as in wrong) stuff in your code:

          • Why are you forcing the connection type to be DirectConnection ? There's rarely a need to specify the type of connection.
          • Why is savedImage a pointer rather than a QImage object ? There's usually no need for that

          Additional questions:

          • Which version of Qt ?
          • On which OS ?

          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
          1
          • J Offline
            J Offline
            John1123
            wrote on last edited by
            #5

            For DirectConnection, I added that because I thought I needed it; Ill take it off. savedImage is used in the file that calls the VideoCapture functions. I'm running QT on 6.6.3 and I'm on windows

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

              You should rather emit the new image from your VideoCapture class rather than fiddling with a variable that it should not know about.

              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
              1
              • J Offline
                J Offline
                John1123
                wrote on last edited by
                #7

                Ok, ill look into emitting the image that it captures, but I still have the problem where capture() wont capture an image

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

                  Did you try to save the image in a file to see how it looks ?

                  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
                  • J Offline
                    J Offline
                    John1123
                    wrote on last edited by John1123
                    #9

                    An image can't be captured in the first place, whenever I call capture it redirects to readyForCapture and isReadyForCapture changes from true to false. This also applies to captureToFile()

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

                      Which version of Qt are you using ?
                      On which OS ?
                      With which device ?

                      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
                      • J Offline
                        J Offline
                        John1123
                        wrote on last edited by
                        #11

                        I'm running QT on 6.6.3, I'm on windows, and I'm using my webcam

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

                          Which version of Windows ?
                          What is the model of your webcam ?

                          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
                          • J Offline
                            J Offline
                            John1123
                            wrote on last edited by
                            #13

                            my webcam is a Logi C615 HD WebCam, and im on windows 10

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

                              Can you check again with 6.7 ?

                              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
                              • J Offline
                                J Offline
                                John1123
                                wrote on last edited by
                                #15

                                I've checked again in 6.7 and it still doesn't work.

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

                                  Ok, then can you switch the backend to use the native rather than ffmpeg ?

                                  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
                                  • J Offline
                                    J Offline
                                    John1123
                                    wrote on last edited by
                                    #17

                                    How would I do that?

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

                                      It's described here.

                                      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
                                      1
                                      • J Offline
                                        J Offline
                                        John1123
                                        wrote on last edited by John1123
                                        #19

                                        So I've tried it, and now isReadyForCapture doesn't change to false after capture() is called but it still doesn't capture an image

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

                                          Can you provide a minimal compilable example that shows this behaviour ?

                                          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

                                          • Login

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