Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. What module should I use for streaming C++ QImage objects into QML?

What module should I use for streaming C++ QImage objects into QML?

Scheduled Pinned Locked Moved Solved Qt 6
10 Posts 3 Posters 2.0k 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.
  • W Offline
    W Offline
    wooseokyourself
    wrote on last edited by
    #1

    Hi! I'm just start learning qt for developing desktop application. In particular, the front-end is implemented in QML and the back-end is implemented in C++.

    My Qt6 app uses camera device. To control the camera device, I need to use the external C++ library provided by the camera vendor, so I can't use QCamera class of the QT Multimedia module.
    So I made my own Camera class for handling streaming, which converts new raw frame to QImage and pushed it into a one-way queue. Whenever a new QImage is pushed in the queue, a signal emitted.
    Now I want to create a slot that is connected to this signal and renders the QImage to QML.

    I've searched many forums, but I still can't figure it out. Some Qt5 examples use QAbstractVideoSurface, which seems to be no longer valid in Qt6. Some examples use QQuickImageProvider, but that doesn't seem like a good way to keep updating images.

    Any advice will be appreciated

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

      Hi and welcome to devnet,

      Beside the controlling that you do with that external library, is the camera itself usable through QtMultimedia ?

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

      W 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi and welcome to devnet,

        Beside the controlling that you do with that external library, is the camera itself usable through QtMultimedia ?

        W Offline
        W Offline
        wooseokyourself
        wrote on last edited by
        #3

        @SGaist
        I think no.
        Just to add a little background, the camera communicates via GigE and the external library is ArenaSDK from Lucid Vision Labs, and the camera device can be controlled with the GenICam API. Also I need to handle multiple streaming cameras.

        I think when I import a physical camera device as an object from the external library, this camera device will not be looked up with QMediaDevices::videoInputs() .
        If I implement a custom camera class that inherits from QCameraDevice and conforms to the GenICam API, I might be able to use QtMultimedia. But it doesn't seem to provide QCameraDevice as an abstract class.


        By the way, I found a Qt5 example provided by the external library; Create a QVideoFrame using QImage and take it as an argument of QAbstractVideoSurface::present() .

        void pushImage(Arena::IImage* pImage)
        {
        	if (m_isStreaming)
        	{
        		QVideoFrame videoFrame(
        			QImage(
        				(uchar*)(pImage->GetData()),
        				pImage->GetWidth(),
        				pImage->GetHeight(),
        				QImage::Format::Format_RGB32));
        		m_pSurface->present(videoFrame);
        	}
        }
        

        Widgets are used instead of QML in this example, but I've seen some Qt5 examples in which QAbstractVideoSurface is binded into QML's VideoOutput.

        Only now did the question become a bit clearer.

        1. Constructing QVideoFrame with QImage is deprecated in Qt6. Is there still a way to do it in Qt6?
        2. If not, is there any other way to put QImage in VideoOutput?
        eyllanescE 2 Replies Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          With Qt 5, you could have gone with a custom plugin or QMediaObject but I currently don't know for Qt 6.

          Maybe something to bring to mailing list. Did you already check the bug tracker ?

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

          W 1 Reply Last reply
          0
          • W wooseokyourself

            @SGaist
            I think no.
            Just to add a little background, the camera communicates via GigE and the external library is ArenaSDK from Lucid Vision Labs, and the camera device can be controlled with the GenICam API. Also I need to handle multiple streaming cameras.

            I think when I import a physical camera device as an object from the external library, this camera device will not be looked up with QMediaDevices::videoInputs() .
            If I implement a custom camera class that inherits from QCameraDevice and conforms to the GenICam API, I might be able to use QtMultimedia. But it doesn't seem to provide QCameraDevice as an abstract class.


            By the way, I found a Qt5 example provided by the external library; Create a QVideoFrame using QImage and take it as an argument of QAbstractVideoSurface::present() .

            void pushImage(Arena::IImage* pImage)
            {
            	if (m_isStreaming)
            	{
            		QVideoFrame videoFrame(
            			QImage(
            				(uchar*)(pImage->GetData()),
            				pImage->GetWidth(),
            				pImage->GetHeight(),
            				QImage::Format::Format_RGB32));
            		m_pSurface->present(videoFrame);
            	}
            }
            

            Widgets are used instead of QML in this example, but I've seen some Qt5 examples in which QAbstractVideoSurface is binded into QML's VideoOutput.

            Only now did the question become a bit clearer.

            1. Constructing QVideoFrame with QImage is deprecated in Qt6. Is there still a way to do it in Qt6?
            2. If not, is there any other way to put QImage in VideoOutput?
            eyllanescE Offline
            eyllanescE Offline
            eyllanesc
            wrote on last edited by
            #5
            This post is deleted!
            1 Reply Last reply
            0
            • W wooseokyourself

              @SGaist
              I think no.
              Just to add a little background, the camera communicates via GigE and the external library is ArenaSDK from Lucid Vision Labs, and the camera device can be controlled with the GenICam API. Also I need to handle multiple streaming cameras.

              I think when I import a physical camera device as an object from the external library, this camera device will not be looked up with QMediaDevices::videoInputs() .
              If I implement a custom camera class that inherits from QCameraDevice and conforms to the GenICam API, I might be able to use QtMultimedia. But it doesn't seem to provide QCameraDevice as an abstract class.


              By the way, I found a Qt5 example provided by the external library; Create a QVideoFrame using QImage and take it as an argument of QAbstractVideoSurface::present() .

              void pushImage(Arena::IImage* pImage)
              {
              	if (m_isStreaming)
              	{
              		QVideoFrame videoFrame(
              			QImage(
              				(uchar*)(pImage->GetData()),
              				pImage->GetWidth(),
              				pImage->GetHeight(),
              				QImage::Format::Format_RGB32));
              		m_pSurface->present(videoFrame);
              	}
              }
              

              Widgets are used instead of QML in this example, but I've seen some Qt5 examples in which QAbstractVideoSurface is binded into QML's VideoOutput.

              Only now did the question become a bit clearer.

              1. Constructing QVideoFrame with QImage is deprecated in Qt6. Is there still a way to do it in Qt6?
              2. If not, is there any other way to put QImage in VideoOutput?
              eyllanescE Offline
              eyllanescE Offline
              eyllanesc
              wrote on last edited by eyllanesc
              #6

              @wooseokyourself If you have the QImage then copy the bits to QVideoFrame, something like:

              QImage image(...);
              QVideoFrameFormat video_frame_format(image.size(), QVideoFrameFormat::pixelFormatFromImageFormat(image.format()));
              QVideoFrame video_frame(video_frame_format);
              if(video_frame.map(QVideoFrame::ReadWrite))){
                  std::memcpy(video_frame.bits(0), image.bits(), video_frame.mappedBytes(0));
                  video_frame.unmap(); 
              }
              
              W 1 Reply Last reply
              2
              • eyllanescE eyllanesc

                @wooseokyourself If you have the QImage then copy the bits to QVideoFrame, something like:

                QImage image(...);
                QVideoFrameFormat video_frame_format(image.size(), QVideoFrameFormat::pixelFormatFromImageFormat(image.format()));
                QVideoFrame video_frame(video_frame_format);
                if(video_frame.map(QVideoFrame::ReadWrite))){
                    std::memcpy(video_frame.bits(0), image.bits(), video_frame.mappedBytes(0));
                    video_frame.unmap(); 
                }
                
                W Offline
                W Offline
                wooseokyourself
                wrote on last edited by
                #7

                @eyllanesc Thanks. Your solution works for converting QImage to QVideoFrame.

                1 Reply Last reply
                0
                • SGaistS SGaist

                  With Qt 5, you could have gone with a custom plugin or QMediaObject but I currently don't know for Qt 6.

                  Maybe something to bring to mailing list. Did you already check the bug tracker ?

                  W Offline
                  W Offline
                  wooseokyourself
                  wrote on last edited by
                  #8

                  @SGaist Thanks for reply. But I don't understand what you meant "mailing list" and "bug tracker".
                  Thanks for @eyllanesc 's answer, I could convert QImage to QVideoFrame, but the next bigger problem is how to send C++'s QVideoFrame to QML's VideoOutput. So I didn't use QVideoFrame, but subclassing QQuickPaintedItem for QML's image object and bind it with my custom C++ image provider which update new QImage by using signal-slot.
                  I'm not sure it's best optimized solution, but quite fast as much as I expected.

                  eyllanescE SGaistS 2 Replies Last reply
                  0
                  • W wooseokyourself

                    @SGaist Thanks for reply. But I don't understand what you meant "mailing list" and "bug tracker".
                    Thanks for @eyllanesc 's answer, I could convert QImage to QVideoFrame, but the next bigger problem is how to send C++'s QVideoFrame to QML's VideoOutput. So I didn't use QVideoFrame, but subclassing QQuickPaintedItem for QML's image object and bind it with my custom C++ image provider which update new QImage by using signal-slot.
                    I'm not sure it's best optimized solution, but quite fast as much as I expected.

                    eyllanescE Offline
                    eyllanescE Offline
                    eyllanesc
                    wrote on last edited by eyllanesc
                    #9

                    @wooseokyourself See this example: https://stackoverflow.com/questions/69432427/how-to-use-qvideosink-in-qml-in-qt6/69432938#69432938. In your case it is not necessary to use QImage, just use:

                    QSize size(pImage->GetWidth(), pImage->GetHeight());
                    QVideoFrameFormat video_frame_format(size, QVideoFrameFormat::pixelFormatFromImageFormat(QImage::Format_RGB32));
                    QVideoFrame video_frame(video_frame_format);
                    if(video_frame.map(QVideoFrame::ReadWrite))){
                        std::memcpy(video_frame.bits(0), pImage->GetData(), video_frame.mappedBytes(0));
                        video_frame.unmap(); 
                    }
                    
                    1 Reply Last reply
                    0
                    • W wooseokyourself

                      @SGaist Thanks for reply. But I don't understand what you meant "mailing list" and "bug tracker".
                      Thanks for @eyllanesc 's answer, I could convert QImage to QVideoFrame, but the next bigger problem is how to send C++'s QVideoFrame to QML's VideoOutput. So I didn't use QVideoFrame, but subclassing QQuickPaintedItem for QML's image object and bind it with my custom C++ image provider which update new QImage by using signal-slot.
                      I'm not sure it's best optimized solution, but quite fast as much as I expected.

                      SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @wooseokyourself said in What module should I use for streaming C++ QImage objects into QML?:

                      @SGaist Thanks for reply. But I don't understand what you meant "mailing list" and "bug tracker".

                      The interest mailing list where you can find Qt's developers/maintainers.

                      The bug tracker is well "the place where the bugs are tracked".

                      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

                      • Login

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