Results 1 to 3 of 3

Thread: Render two videos in an application

  1. #1
    Join Date
    Jul 2019
    Qt products

    Question Render two videos in an application

    I am receiving a video stream from an external source (Pupil eye-tracker) frame by frame as a buffer via zmq. I have to process each frame in two ways: draw a bounding box in the image with a certain logic and display it in one view, use those bounding box to crop region of interest and display it in another. The bounding box will always have the same size.

    As a POC, I added two labels to a widget, and each label has a separate thread to handle changePixmap, both of which currently receive the frames from the source. However, I am facing a couple of issues -

    • I am not really sure what is the best way to interact between the two threads - as my second thread uses the bounding box from the first thread to render the region of interest
    • This rendering is not really performant, I see my UI lag after a certain point of time

    As an alternative, I am thinking of moving to a model view approach, where I will use two QAbstractTableModels to store pixel-wise information of the current frame and of the region of interest. Correspondingly, I will create two QImages for each image. I am thinking of a flow like this:

    The buffer will update the data in the first model -> Use a signal to notify the change, I will then convert it to an image and create the bounding box -> Update the pixel indexes with a certain color in the first table corresponding to pixels in the bounding box -> update region of interest in the second table by picking indexes inside bounding box from the previous step.

    I have a few queries with this approach:
    • Is this the best way to approach this problem, which, to me, seems very complicated? Any other thoughts of how I can go about it?
    • What is the best way to store the image as a table, how do I add a numpy array to a TableModel?
    • How should I convert data in a table to an image as fast as possible, should I use setPixel for the QImage and then use setPixmap?

    Any help is greatly appreciated.

  2. #2
    Join Date
    Jan 2006
    Graz, Austria
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Unix/X11 Windows

    Default Re: Render two videos in an application

    Using a model sounds wrong, this is image/pixel data, not something shown in an item view.

    Since you likely want to show the same image in parallel in both views, using two threads sounds also like more trouble than necessary.

    There are likely two approaches

    * Worker thread receives the data and created an image
    * Creates second image applying the crop region
    * Stores both images in variables accessible by the main thread (obviously under protection of a mutex)
    * Notifies the main thread via signal of the new images

    * Slot on the main thread retrieves the two images and puts them into each QLabel
    * Conversion from QImage to QPixmap can take a bit of processing time if the image data formats are not the same, e.g. color depth begin different

    * Worker thread receives data and creates an OpenGL texture
    * Performs cropping in OpenGL generating a second texture
    * Use OpenGL widgets for displaying the two textures


  3. #3
    Join Date
    Jan 2006
    Warsaw, Poland
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits

    Default Re: Render two videos in an application

    Regarding approach 2, you don't even need to crop to get the second texture, just modify coordinates of the texture when displaying it in the second view so that only the needed part is rasterized.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.

Similar Threads

  1. Render a QWebEnginePage from one non gui to gui application
    By bibhukalyana in forum Qt Programming
    Replies: 1
    Last Post: 25th February 2018, 09:04
  2. Qt 5.4.2 cannot play videos on xp?
    By Nya in forum Qt Programming
    Replies: 4
    Last Post: 13th June 2015, 08:54
  3. QWebview render too slow in real time application
    By zlxwd in forum Qt Programming
    Replies: 0
    Last Post: 30th July 2014, 04:33
  4. How to render HTML file in QT widget application
    By nestuser in forum Qt Programming
    Replies: 1
    Last Post: 27th August 2012, 07:31
  5. QGLWidget render or QGraphicsView with GL viewport render
    By QTInfinity in forum Qt Programming
    Replies: 2
    Last Post: 28th November 2011, 11:34

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.