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. QImage to QPixmap is too slow
Forum Updated to NodeBB v4.3 + New Features

QImage to QPixmap is too slow

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 6 Posters 7.9k 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.
  • kshegunovK kshegunov

    @betterorbest
    Hello,
    There are options depending on your setup, however you should provide a little more information on what you're trying to do. For example is this is a multithreaded application, do you block the event loop for other things etc. A code sample could also be useful, and will probably attract better answers.

    Kind regards.

    betterorbestB Offline
    betterorbestB Offline
    betterorbest
    wrote on last edited by
    #3

    @kshegunov
    Hi
    I want to show my image streams in Qt's ui. Now I have to first convert my image from the hardware data streams to a qImage, then convert the qImage to QPixmap and finally use QLabel::setPixmap(qPixmap) to show it in a QLabel. I just mean that QPixmap::fromImage(qImage) is too slow and takes around 30ms for qimage with 1280 * 960 resolution. So I want to find a faster way to show my image streams.
    Thank you for your help.

    kshegunovK ? 2 Replies Last reply
    0
    • Y Offline
      Y Offline
      yoavmil
      wrote on last edited by
      #4

      A threaded pipe-line sounds right.
      do this in 3 steps:
      a) 1 thread reads data to qimage
      b) 1 thread converts qimage to qpixmap
      c) gui thread shows the qpixmap.

      use signal/slots between threads

      betterorbestB 1 Reply Last reply
      0
      • betterorbestB betterorbest

        @kshegunov
        Hi
        I want to show my image streams in Qt's ui. Now I have to first convert my image from the hardware data streams to a qImage, then convert the qImage to QPixmap and finally use QLabel::setPixmap(qPixmap) to show it in a QLabel. I just mean that QPixmap::fromImage(qImage) is too slow and takes around 30ms for qimage with 1280 * 960 resolution. So I want to find a faster way to show my image streams.
        Thank you for your help.

        kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on last edited by
        #5

        @betterorbest
        That's a big image. Have you tried drawing the image directly, instead of converting it to a pixmap first? If that doesn't work have you tried drawing the image on a GL surface?

        @yoavmil

        b) 1 thread converts qimage to qpixmap

        That ain't happening. QPixmap is not reentrant.

        Read and abide by the Qt Code of Conduct

        betterorbestB 1 Reply Last reply
        0
        • betterorbestB betterorbest

          @kshegunov
          Hi
          I want to show my image streams in Qt's ui. Now I have to first convert my image from the hardware data streams to a qImage, then convert the qImage to QPixmap and finally use QLabel::setPixmap(qPixmap) to show it in a QLabel. I just mean that QPixmap::fromImage(qImage) is too slow and takes around 30ms for qimage with 1280 * 960 resolution. So I want to find a faster way to show my image streams.
          Thank you for your help.

          ? Offline
          ? Offline
          A Former User
          wrote on last edited by A Former User
          #6

          @betterorbest said:

          Now I have to first convert my image from the hardware data streams

          The fastest way possible is to move the raw pixel data directly into an OpenGL Pixel Buffer Object and do all the transformations / rendering in the GPU.

          1 Reply Last reply
          2
          • kshegunovK kshegunov

            @betterorbest
            That's a big image. Have you tried drawing the image directly, instead of converting it to a pixmap first? If that doesn't work have you tried drawing the image on a GL surface?

            @yoavmil

            b) 1 thread converts qimage to qpixmap

            That ain't happening. QPixmap is not reentrant.

            betterorbestB Offline
            betterorbestB Offline
            betterorbest
            wrote on last edited by
            #7

            @kshegunov
            Thank you for your answer. I thought there may be some faster way without using opengl. But if this is the fact, I will finally try the opengGl. In other hand, drawing the image directly seems to be as slow as QPixmap::from(qImage).

            kshegunovK 1 Reply Last reply
            0
            • Y yoavmil

              A threaded pipe-line sounds right.
              do this in 3 steps:
              a) 1 thread reads data to qimage
              b) 1 thread converts qimage to qpixmap
              c) gui thread shows the qpixmap.

              use signal/slots between threads

              betterorbestB Offline
              betterorbestB Offline
              betterorbest
              wrote on last edited by
              #8

              @yoavmil
              I tried your advice once. But the conversion from qImage to qPixmap is stiil the bottle neck. Thank you for your advice.

              @Moderators
              Thank you. I will try the openGl advice.

              1 Reply Last reply
              0
              • Q Offline
                Q Offline
                Q139
                wrote on last edited by
                #9

                You could cut image to 2 or 4 or more parts , spread load between threads while processing and later reconstruct image to 1.

                1 Reply Last reply
                0
                • betterorbestB betterorbest

                  @kshegunov
                  Thank you for your answer. I thought there may be some faster way without using opengl. But if this is the fact, I will finally try the opengGl. In other hand, drawing the image directly seems to be as slow as QPixmap::from(qImage).

                  kshegunovK Offline
                  kshegunovK Offline
                  kshegunov
                  Moderators
                  wrote on last edited by
                  #10

                  @betterorbest said:

                  Thank you for your answer. I thought there may be some faster way without using opengl.

                  Nope. OpenGL has facilities for such things, while the ordinary QPainter based approach doesn't. So I'd go with what @Wieland suggested.

                  Read and abide by the Qt Code of Conduct

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

                    Hi,

                    Out of curiosity, what is the format of your images ?

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

                    betterorbestB 1 Reply Last reply
                    0
                    • SGaistS SGaist

                      Hi,

                      Out of curiosity, what is the format of your images ?

                      betterorbestB Offline
                      betterorbestB Offline
                      betterorbest
                      wrote on last edited by
                      #12

                      @SGaist
                      The original data streams is raw data. I convert the raw data to color image with QImage::Format_RGB888.

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

                        Are you only showing that 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

                        • Login

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