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. Using a label to display large images in QT GUI
QtWS25 Last Chance

Using a label to display large images in QT GUI

Scheduled Pinned Locked Moved Solved General and Desktop
opencvqlabelimage displayopenglpixmap
5 Posts 3 Posters 2.5k 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.
  • R Offline
    R Offline
    rtavakko
    wrote on 2 Aug 2019, 22:57 last edited by rtavakko 8 Feb 2019, 22:57
    #1

    Hi guys,

    My application does live processing of images using OpenCV and shows the result on an output display / monitor. I'm using a 'label' for this, first converting my OpenCV matrix to a QImage and then I use that QImage to create a pixmap for the label. It works ok for small labels but if the label is covering the entire size of say a 1920 x 1080 display, setting the pixmap slows everything down by a factor of 6 which is inhumane (it goes from processing time of ~10 mS to ~60 mS).

    Can anyone else confirm that this is the case?

    Is there a faster way of doing this using another type of widget perhaps? OpenGL?

    This is what I'm doing at the moment (videoFrameOut is my OpenCV matrix):

    image = QImage((uchar*)(videoFrameOut.data),videoFrameOut.cols,videoFrameOut.rows, QImage::Format_RGBA8888);
    
    ui -> oLabel -> setAlignment(Qt::AlignCenter);
    ui -> oLabel -> setPixmap(QPixmap::fromImage(image.scaled(QSize(ui->oLabel->width(),ui->oLabel->height()), Qt::KeepAspectRatio, Qt::FastTransformation)));
    
    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 3 Aug 2019, 19:36 last edited by
      #2

      Hi,

      Something is not completely clear, are you always resizing to a smaller version of the image for displaying ?

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

      R 1 Reply Last reply 8 Aug 2019, 02:32
      2
      • C Offline
        C Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on 3 Aug 2019, 20:11 last edited by Chris Kawa 8 Mar 2019, 20:16
        #3

        The first line is nice because it just creates Qt interface over the foreign data without any copies. Unfortunately the rest of it is not as nice.
        I'd say the performance is killed by the amount of copies and resizing you're doing: image.scaled does scaling and creates new buffer, QPixmap::fromImage does another copy, setPixmap is another (potential) copy and then setting that pixmap on a label causes it to re-layout itself and do all sorts of bookkeeping.

        Without going into hardware acceleration (OpenGL or Vulkan) the low hanging fruit is avoiding all those copies.
        Instead of a label inherit a plain QWidget, override paintEvent and draw the image directly with QPainter::drawImage. It will do the scaling and draw on the fly without all those expensive copies.

        1 Reply Last reply
        5
        • S SGaist
          3 Aug 2019, 19:36

          Hi,

          Something is not completely clear, are you always resizing to a smaller version of the image for displaying ?

          R Offline
          R Offline
          rtavakko
          wrote on 8 Aug 2019, 02:32 last edited by
          #4

          @sgaist I have a few small-sized labels of ~130x130 pixels which display a scaled down image (usually 1280x720 or 1920x1080). The bigger label which covers an entire display is what is causing the performance drop. Not knowing whats going on under the hood I would have imagined that downsizing to the smaller labels would be the bottleneck but its the other way round.

          @Chris-Kawa That makes sense, I'll try that.

          There doesn't seem to be any way to set the pixmap from raw data similar to what I'm doing with the QImage, at least not with a uchar array outside of a file, is that right?

          1 Reply Last reply
          0
          • R Offline
            R Offline
            rtavakko
            wrote on 24 Aug 2019, 22:15 last edited by rtavakko
            #5

            An update on this. It works perfectly and its a very low-cost solution. My processing time remains almost the same (~10mS) using this method since the painter does the scaling for you when it draws.

            Thanks for your help guys.

            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