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. Snap Picture Not Working
Qt 6.11 is out! See what's new in the release blog

Snap Picture Not Working

Scheduled Pinned Locked Moved Unsolved General and Desktop
15 Posts 4 Posters 5.6k 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.
  • TrayonT Offline
    TrayonT Offline
    Trayon
    wrote on last edited by
    #4

    I'm aware of that class, I just wanted to prototype with the easy way before messing with anything more complicated. If you could give me insight as to why my initial approach doesn't work, I'd appreciate it. In the mean time, I've also tried to start doing this the "right way", but alas ran into trouble rather fast. I connected the image capture to my class for when I snap a photo, but it's not getting into the function (which prints a simple id through qDebug). Here's my code:

    MainWindow.c:

    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
        //qDebug() << "QCameraInfo: " << checkCameraAvailability();
        QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
        camera = new QCamera(cameras.first());
        imageCapture = new QCameraImageCapture(camera);
    
        connect(imageCapture,&QCameraImageCapture::imageAvailable,this,&MainWindow::testFunc);
    
        camView = new QCameraViewfinder();
        camera->setViewfinder(camView);
        camView->show();
        camera->start();
    
        ui->horizontalLayout->addWidget(camView);
        ui->horizontalLayout->addWidget(&testLabel);
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    void MainWindow::testFunc(int id, QVideoFrame buffer)
    {
        qDebug() << id;
    }
    
    void MainWindow::on_SnapButton_clicked()
    {
        imageCapture->setCaptureDestination(QCameraImageCapture::CaptureToBuffer);
        imageCapture->setBufferFormat(QVideoFrame::Format_Jpeg);
    
        camera->setCaptureMode(QCamera::CaptureStillImage);
    
        camera->searchAndLock();
        imageCapture->capture();
        camera->unlock();
        //testLabel.setPixmap(camView->grab());
    }
    
    1 Reply Last reply
    0
    • TrayonT Offline
      TrayonT Offline
      Trayon
      wrote on last edited by
      #5

      I looked around and read that "imageCapture->capture();" will only capture to a file (and filled up my picture directory). I haven't found any way to trigger a capture to buffer. Can anyone help?

      JonBJ 1 Reply Last reply
      0
      • TrayonT Trayon

        I looked around and read that "imageCapture->capture();" will only capture to a file (and filled up my picture directory). I haven't found any way to trigger a capture to buffer. Can anyone help?

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #6

        @Trayon
        http://doc.qt.io/qt-5/qcameraimagecapture.html#CaptureDestination-enum

        ?

        1 Reply Last reply
        0
        • TrayonT Offline
          TrayonT Offline
          Trayon
          wrote on last edited by
          #7

          My code set that value already. You can see it in the last function definition 'on_SnapButton_clicked()'

          1 Reply Last reply
          0
          • TrayonT Offline
            TrayonT Offline
            Trayon
            wrote on last edited by
            #8

            Actually, inspired by your post, I looked at isCaptureDestinationSupported. Apparently a buffer is not supported... Does anyone know why this could be?

            1 Reply Last reply
            0
            • mranger90M Offline
              mranger90M Offline
              mranger90
              wrote on last edited by
              #9

              Did you try connecting the imageCaptured signal (forgive the old syntax) ?

              connect(m_pImageCapture, SIGNAL(imageCaptured(int,QImage)), this, SLOT(processCapturedImage(int,QImage)));
              

              Then the slot:
              void xxxxx::processCapturedImage(int requestId, const QImage& img)

              You can extract from the QImage passed to the slot.

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

                Since you want to send it to a REST service, why not exploit the fact that having that temporary file allows you to retry a failed upload without clogging the memory used by your application. You can delete the file once you're done with it.

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

                  I looked into using the QImage, but I would either have to convert it to a QVideoFrame (and I couldn't find how), or perform a tedious manual conversion. I'd rather find out why the buffer option isn't supported and fix it rather than hack my way around. I'm going to try on my Linux machine with a spare webacam I found and see if that works.

                  @SGaist
                  I don't see why a temporary image would fare better than a buffer. I would have to read the file and re-fill my buffer if it fails, resulting in more time lost.

                  1 Reply Last reply
                  0
                  • TrayonT Offline
                    TrayonT Offline
                    Trayon
                    wrote on last edited by
                    #12

                    Apparently it works on Linux but not Windows. Anybody have some insight as to why?

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

                      Because the windows platform camera plugin doesn't implement that option.

                      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
                      • TrayonT Offline
                        TrayonT Offline
                        Trayon
                        wrote on last edited by
                        #14

                        Is there a file I can download that implements it for Windows, or is this a problem of QT having to get around to it?

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

                          If there was, it would be part of the plugin. See the DSCameraSession class.

                          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