Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Setting QML VideoOutput Source using (C++) QCamera with ViewFinder set to a QAbstractVideoSurface

Setting QML VideoOutput Source using (C++) QCamera with ViewFinder set to a QAbstractVideoSurface

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
15 Posts 6 Posters 3.6k Views 3 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.
  • D Offline
    D Offline
    DomTheDuck
    wrote on last edited by DomTheDuck
    #1

    A similar solution was provided for my problem ( https://forum.qt.io/topic/27196/use-qml-videooutput-item-with-c-qmediaplayer ) using a QMediaPlayer.

    However my aim is to display a live camera feed rather than play a media file. I setup the camera using QCamera and passed an instance of my implementation of the QAbstractVideoSurface class to the viewFinder of the QCamera so it can be a QML Videoutput source. Everything seems to be firing off properly, but there was no display on the QML GUI side when I ran my program any ideas why this might be?

    Let me know if my question is unclear and if I need to provide code. Thank you in advance for your help.

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

      Hi and welcome to devnet,

      What video frame format are you using ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      ODБOïO D 2 Replies Last reply
      0
      • SGaistS SGaist

        Hi and welcome to devnet,

        What video frame format are you using ?

        ODБOïO Offline
        ODБOïO Offline
        ODБOï
        wrote on last edited by
        #3

        hi,

        @DomTheDuck said in Setting QML VideoOutput Source using (C++) QCamera with ViewFinder set to a QAbstractVideoSurface:

        but there was no display on the QML

        What about the sound ?

        D 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi and welcome to devnet,

          What video frame format are you using ?

          D Offline
          D Offline
          DomTheDuck
          wrote on last edited by
          #4

          @SGaist Thanks for the quick response:

          The only QVideoframe format that had a readily available QImage equivalent was "Format_ARGB32" The other potential video frame formats available with the camera I am using did not have a QImage equivalent.

          1 Reply Last reply
          0
          • ODБOïO ODБOï

            hi,

            @DomTheDuck said in Setting QML VideoOutput Source using (C++) QCamera with ViewFinder set to a QAbstractVideoSurface:

            but there was no display on the QML

            What about the sound ?

            D Offline
            D Offline
            DomTheDuck
            wrote on last edited by
            #5

            @LeLev

            I do not think my camera has microphone capabilities, that being said, I did not hear any surrounding sounds being picked up.

            Pablo J. RoginaP 1 Reply Last reply
            0
            • D DomTheDuck

              @LeLev

              I do not think my camera has microphone capabilities, that being said, I did not hear any surrounding sounds being picked up.

              Pablo J. RoginaP Offline
              Pablo J. RoginaP Offline
              Pablo J. Rogina
              wrote on last edited by
              #6

              @DomTheDuck you may want to take a look at this OpenCV wrapper for QML just in case, either to use it directly or to check what/how they're doing things there.

              Upvote the answer(s) that helped you solve the issue
              Use "Topic Tools" button to mark your post as Solved
              Add screenshots via postimage.org
              Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

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

                Out of curiosity, what is the problem with the Camera qml type ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                D 1 Reply Last reply
                0
                • SGaistS SGaist

                  Out of curiosity, what is the problem with the Camera qml type ?

                  D Offline
                  D Offline
                  DomTheDuck
                  wrote on last edited by
                  #8

                  @SGaist None at all, I just want to do a lot of backend (c++) work, and with using the QML camera I would need to get that feed to the backend, do some processing and then send it back to the QML front end. It seems inefficient to therefore use QML Camera.

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

                    What processing do you need ?

                    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
                    • G Offline
                      G Offline
                      gomgom
                      wrote on last edited by
                      #10

                      @domtheduck
                      Hi, were you ever able to make this work?

                      I'm trying to use the zxing library to read some Qr codes, and this is done by using this library as part of a QAbstractVideoFilter applied in qml on the camera's video output.
                      I might be wrong but to me this type of processing definitely doesn't belong in QML, where I just want to describe the user interface, but definitely don't want to describe any processing (I know the filter will run in C, but still I don't see why the controls, Qr code results etc.. would have to go back and forth between the QML and C++ world, all this should stay in C++. The filter scheme being used here not to modify what the user sees, but to analyze frames).

                      So there you go, were you able to figure it out? I can get something on my display, but the video doesn't show what's being captured (just flickering blank frames).

                      I have defined this class:

                      class PxQCameraAsSource : public QCamera
                      {
                        Q_OBJECT
                        Q_PROPERTY(QAbstractVideoSurface* videoSurface READ getVideoSurface WRITE setVideoSurface )
                      public:
                        explicit PxQCameraAsSource(QCamera::Position position, QObject *parent);
                      
                      public slots:
                        void setVideoSurface(QAbstractVideoSurface* surface);
                        QAbstractVideoSurface* getVideoSurface();
                      
                      private:
                        QAbstractVideoSurface* _surface;
                      };
                      

                      And for my .cpp:

                      PxQCameraAsSource::PxQCameraAsSource(QCamera::Position position, QObject *parent) :
                        QCamera (position, parent)
                      {
                      }
                      
                      void PxQCameraAsSource::setVideoSurface(QAbstractVideoSurface* newSurface)
                      {
                        _surface = newSurface;
                        setViewfinder(_surface);
                      }
                      
                      QAbstractVideoSurface* PxQCameraAsSource::getVideoSurface()
                      {
                        return _surface;
                      }
                      

                      I guess I must be missing initialization steps, or some property/calls, but I have no idea which ones :-)

                      1 Reply Last reply
                      0
                      • GrecKoG Offline
                        GrecKoG Offline
                        GrecKo
                        Qt Champions 2018
                        wrote on last edited by
                        #11

                        @gomgom
                        Can you use libraries that already do that?

                        Like https://github.com/ftylitak/qzxing/ or https://github.com/swex/QZXingNu

                        G 1 Reply Last reply
                        0
                        • GrecKoG GrecKo

                          @gomgom
                          Can you use libraries that already do that?

                          Like https://github.com/ftylitak/qzxing/ or https://github.com/swex/QZXingNu

                          G Offline
                          G Offline
                          gomgom
                          wrote on last edited by
                          #12

                          @grecko Hi, these libs operate in the QML world (the filter is implemented there), which is what I am trying to avoid. For now I'm using QZXingNu, it works but I'm not happy with it from an architecture point of view.
                          I'd really like to limit the QML's role to displaying the camera viewfinder, but not to handle the Qr code reader result etc (even if it just passes the result on to the C++ side, it doesn't seem to make any sense to me)...

                          Pablo J. RoginaP 1 Reply Last reply
                          0
                          • G gomgom

                            @grecko Hi, these libs operate in the QML world (the filter is implemented there), which is what I am trying to avoid. For now I'm using QZXingNu, it works but I'm not happy with it from an architecture point of view.
                            I'd really like to limit the QML's role to displaying the camera viewfinder, but not to handle the Qr code reader result etc (even if it just passes the result on to the C++ side, it doesn't seem to make any sense to me)...

                            Pablo J. RoginaP Offline
                            Pablo J. RoginaP Offline
                            Pablo J. Rogina
                            wrote on last edited by
                            #13

                            @gomgom said in Setting QML VideoOutput Source using (C++) QCamera with ViewFinder set to a QAbstractVideoSurface:

                            these libs operate in the QML world (the filter is implemented there)

                            I guess the thing is perhaps there's a compelling reason (which I don't know) why the Qt developers provided an easy way to implement video filtering in QML but that same capability is not (or at least not easily) accessible to the C++ part...

                            Upvote the answer(s) that helped you solve the issue
                            Use "Topic Tools" button to mark your post as Solved
                            Add screenshots via postimage.org
                            Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

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

                              Hi,

                              Are you looking for QAbstractVideoFilter ?

                              Interested in AI ? www.idiap.ch
                              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                              G 1 Reply Last reply
                              0
                              • SGaistS SGaist

                                Hi,

                                Are you looking for QAbstractVideoFilter ?

                                G Offline
                                G Offline
                                gomgom
                                wrote on last edited by
                                #15

                                @sgaist
                                Hi,
                                Not really, no. The QZXingNu already provides a class based on QAbstractVideoFilter. But it then exposes this to the QML side, and examples create a camera, video output and connect the filter all in QML.
                                What I'm trying to do is to instantiate a QCamera and filter un C++, and somehow connect this to a QML VideoOutput. I am missing the glue in between :-)

                                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