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. QML Camera and Video Probe (probe not working)
QtWS25 Last Chance

QML Camera and Video Probe (probe not working)

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 2 Posters 2.3k Views
  • 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
    #1

    I'm trying to use a QML camera to get the raw data from a webcam and send it to a server for image recognition. I'm using a video probe for this purpose, but the probe doesn't seem to emit the signal I need to process the frame.

    (I've posted what I'm trying to do before, but my solutions weren't cross-platform, and failed pretty hard on Android)

    Here's my code:

    FrameHandler.cpp:

    #include "framehandler.h"
    
    FrameHandler::FrameHandler(QQmlApplicationEngine *engine)
    {
    
        QCamera *camera;
        QObject *qmlCamera = engine->rootObjects().at(0)->findChild<QObject*>("qmlCam");
        QVideoProbe probe;
    
        camera = qvariant_cast<QCamera*>(qmlCamera->property("mediaObject"));
    
        //QObject::connect(&probe,SIGNAL(videoFrameProbed(QVideoFrame)),this,SLOT(handleFrame(QVideoFrame)));
        connect(&probe,&QVideoProbe::videoFrameProbed,this,&FrameHandler::handleFrame);
        probe.setSource(camera);
    }
    
    void FrameHandler::handleFrame(QVideoFrame frame)
    {
        qDebug() << "In handleFrame";
    }
    
    

    main.cpp:

    #include <QGuiApplication>
    #include "framehandler.h"
    
    int main(int argc, char *argv[])
    {
        QGuiApplication app(argc, argv);
    #if defined(Q_OS_WIN)
        QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    #endif
    
        QQmlApplicationEngine engine;
        engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    
        FrameHandler frameHandler(&engine);
    
    
        return app.exec();
    }
    
    

    main.qml:

    import QtQuick 2.9
    import QtQuick.Controls 1.2
    import QtMultimedia 5.3
    import "qrc:/"
    
    ApplicationWindow {
      visible: true
      width: 640
      height: 480
      title: qsTr("QML Camera Demo")
    
      Camera {
        id: camera
        objectName: "qmlCam"
    
        imageCapture {
          onImageCaptured: {
            photoPreview.source = preview
            photoPreview.visible = true;
            previewTimer.running = true;
          }
        }
      }
    
      VideoOutput {
        id: viewfinder
        source: camera
        anchors.fill: parent
      }
    
      Image {
        id: photoPreview
        anchors.fill: viewfinder
      }
    
      Timer {
        id: previewTimer
        interval: 2000
        onTriggered: photoPreview.visible = false;
      }
    
      CaptureButton {
        anchors.right: parent.right
        anchors.verticalCenter: parent.verticalCenter
        diameter: 50
      }
    }
    
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What version of Qt are you using ?
      On what platform ?
      With which compiler ?

      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
        #3

        5.9.3
        Linux
        GCC-64

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

          QVideoProbe is not available on all platforms. See this matrix.

          Do you want to do the face recognition on one specific image ?

          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
            #5

            The charts don't seem to correspond to operating system directly (except maybe Android). I didn't see any QVideoProbe class there. Is it a subclass of one of these?

            Also, it should work according to this source:

            https://stackoverflow.com/questions/28041741/qt-qml-camera-to-c-qimage-on-android/33238150

            The solution that Waldez Junior proposed apparently works on Android. I also tried it on Windows with no luck. Also, I may sound naive asking this, but why don't the QT developers put tests that check the OS and tell the programmer that his work is in vain?

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

              Also, yes. One specific image.

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

                Whoops, made a noob mistake and didn't declare the objects in the header file, so they went out of scope and got deleted. Fixed that, but now the frames getting fed in aren't filled with any data (frame.mappedBytes = 0). I also tried inheriting from an AbstractVideoSurface to see if I could get the data from the 'present' function, but it's not even getting inside (it's now declared in main).

                Here's how I have my main.cpp:

                #include <QGuiApplication>
                #include "framehandler.h"
                #include "cameraframegrabber.h"
                
                int main(int argc, char *argv[])
                {
                    QGuiApplication app(argc, argv);
                #if defined(Q_OS_WIN)
                    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
                #endif
                
                    QQmlApplicationEngine engine;
                    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
                
                    QObject *qmlCamera = engine.rootObjects().at(0)->findChild<QObject*>("qmlCam");
                
                    QCamera *camera = qvariant_cast<QCamera*>(qmlCamera->property("mediaObject"));
                
                    CameraFrameGrabber *cameraFrameGrabber = new CameraFrameGrabber();
                    camera->setViewfinder(cameraFrameGrabber);
                
                    //camera->start(); // I tried this too, but it didn't help.
                
                    return app.exec();
                }
                
                
                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  IIRC, on Android you get a texture.

                  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
                    #9

                    This is on Linux. Is it the same there?

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

                      Has anyone tried to use the media probe or abstract media surface inheritance to get the information? Has anyone succeeded beofore?

                      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