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. Reproduce image watch
QtWS25 Last Chance

Reproduce image watch

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 3 Posters 571 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.
  • W Offline
    W Offline
    wujie
    wrote on 1 Apr 2024, 02:26 last edited by
    #1

    How to build a widget like image watch with high performance?I tried to add millions of pixel items to the scene, but it was not very smooth

    P 1 Reply Last reply 1 Apr 2024, 02:58
    0
    • W wujie
      1 Apr 2024, 02:26

      How to build a widget like image watch with high performance?I tried to add millions of pixel items to the scene, but it was not very smooth

      P Offline
      P Offline
      Pl45m4
      wrote on 1 Apr 2024, 02:58 last edited by Pl45m4 4 Jan 2024, 04:32
      #2

      @wujie

      What do you mean by image watch? A clock widget? Or an image "watcher"?

      I tried to add millions of pixel items to the scene, but it was not very smooth

      What is a "pixel item"? A QGraphicsItem?!
      Why do you need millions of items?

      In general all I can say, reduce the number of rendered items at a time.
      Here is an example:

      • https://doc.qt.io/qt-6/qtwidgets-graphicsview-chip-example.html

      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      W 2 Replies Last reply 1 Apr 2024, 14:33
      0
      • P Pl45m4
        1 Apr 2024, 02:58

        @wujie

        What do you mean by image watch? A clock widget? Or an image "watcher"?

        I tried to add millions of pixel items to the scene, but it was not very smooth

        What is a "pixel item"? A QGraphicsItem?!
        Why do you need millions of items?

        In general all I can say, reduce the number of rendered items at a time.
        Here is an example:

        • https://doc.qt.io/qt-6/qtwidgets-graphicsview-chip-example.html
        W Offline
        W Offline
        wujie
        wrote on 1 Apr 2024, 14:33 last edited by
        #3

        @Pl45m4 Forgiving my rough questioning content。 Image Watch is the OpenCV's official plugin for showing cv::Mat. A pixel item is indeed QGraphicsItem (class pixel : public QGraphicsItem ), and a 1024x1024 image has million pixel items. All items must be displayed when necessary. It is possible to encounter higher resolution images as well。So I want to build an image viewer that is not significantly different in performance from image watch

        P 1 Reply Last reply 1 Apr 2024, 15:27
        0
        • P Pl45m4
          1 Apr 2024, 02:58

          @wujie

          What do you mean by image watch? A clock widget? Or an image "watcher"?

          I tried to add millions of pixel items to the scene, but it was not very smooth

          What is a "pixel item"? A QGraphicsItem?!
          Why do you need millions of items?

          In general all I can say, reduce the number of rendered items at a time.
          Here is an example:

          • https://doc.qt.io/qt-6/qtwidgets-graphicsview-chip-example.html
          W Offline
          W Offline
          wujie
          wrote on 1 Apr 2024, 14:44 last edited by
          #4

          @Pl45m4 I also referred to the chip project to do it。But there are two bottlenecks here, one is that creating millions of QGraphicsItems in the scene takes a lot of time, and the other is when displaying all the items. Dragging the viewport becomes very slow.Can you provide some suggestions for these two bottlenecks?thanks

          1 Reply Last reply
          0
          • W wujie
            1 Apr 2024, 14:33

            @Pl45m4 Forgiving my rough questioning content。 Image Watch is the OpenCV's official plugin for showing cv::Mat. A pixel item is indeed QGraphicsItem (class pixel : public QGraphicsItem ), and a 1024x1024 image has million pixel items. All items must be displayed when necessary. It is possible to encounter higher resolution images as well。So I want to build an image viewer that is not significantly different in performance from image watch

            P Offline
            P Offline
            Pl45m4
            wrote on 1 Apr 2024, 15:27 last edited by Pl45m4 4 Jan 2024, 16:28
            #5

            @wujie said in Reproduce image watch:

            All items must be displayed when necessary

            Yeah, "when necessary". But never all at once. So you never need a million items at the same time.

            But why is one pixel, one QGraphicsItem?
            I think this is already bad design and the wrong approach.

            Edit:

            Consider looking into QImage and QPixmap classes

            • https://doc.qt.io/qt-6/qimage.html
            • https://doc.qt.io/qt-6/qpixmap.html

            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            W 1 Reply Last reply 2 Apr 2024, 01:10
            2
            • P Pl45m4
              1 Apr 2024, 15:27

              @wujie said in Reproduce image watch:

              All items must be displayed when necessary

              Yeah, "when necessary". But never all at once. So you never need a million items at the same time.

              But why is one pixel, one QGraphicsItem?
              I think this is already bad design and the wrong approach.

              Edit:

              Consider looking into QImage and QPixmap classes

              • https://doc.qt.io/qt-6/qimage.html
              • https://doc.qt.io/qt-6/qpixmap.html
              W Offline
              W Offline
              wujie
              wrote on 2 Apr 2024, 01:10 last edited by
              #6

              @Pl45m4 This will make it easy to view the pixel values of the image。

              P 1 Reply Last reply 2 Apr 2024, 01:50
              0
              • W wujie
                2 Apr 2024, 01:10

                @Pl45m4 This will make it easy to view the pixel values of the image。

                P Offline
                P Offline
                Pl45m4
                wrote on 2 Apr 2024, 01:50 last edited by Pl45m4 4 Feb 2024, 02:25
                #7

                @wujie said in Reproduce image watch:

                This will make it easy to view the pixel values of the image。

                This is also possible when having a QImage or QPixmap on a widget, or even the whole image as a single QGraphicsItem (QGraphicsPixmapItem).
                One item for every pixel is really pretty bad. The design and performance-wise.

                I remember, a while ago I've made an example for a user here. I know OpenCV quite well and it's like the OpenCV "namedWindow" (produced by imshow()) where you can zoom and hover over pixels to check the RGB or grayscale value.
                Lemme check, if I can find it. You can also use the search function here on the forum.

                Edit:

                Here, I found it:

                • https://forum.qt.io/post/761603

                The code is also in the topic some comments below my GIF.

                I used a custom QLabel class and its built-in setPixmap function.
                Surely it can be optimized, but might be a good point to start with.


                If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                ~E. W. Dijkstra

                W 1 Reply Last reply 2 Apr 2024, 12:35
                3
                • P Pl45m4
                  2 Apr 2024, 01:50

                  @wujie said in Reproduce image watch:

                  This will make it easy to view the pixel values of the image。

                  This is also possible when having a QImage or QPixmap on a widget, or even the whole image as a single QGraphicsItem (QGraphicsPixmapItem).
                  One item for every pixel is really pretty bad. The design and performance-wise.

                  I remember, a while ago I've made an example for a user here. I know OpenCV quite well and it's like the OpenCV "namedWindow" (produced by imshow()) where you can zoom and hover over pixels to check the RGB or grayscale value.
                  Lemme check, if I can find it. You can also use the search function here on the forum.

                  Edit:

                  Here, I found it:

                  • https://forum.qt.io/post/761603

                  The code is also in the topic some comments below my GIF.

                  I used a custom QLabel class and its built-in setPixmap function.
                  Surely it can be optimized, but might be a good point to start with.

                  W Offline
                  W Offline
                  wujie
                  wrote on 2 Apr 2024, 12:35 last edited by
                  #8

                  @Pl45m4 said in Reproduce image watch:

                  This is also possible when having a QImage or QPixmap on a widget, or even the whole image as a single QGraphicsItem (QGraphicsPixmapItem).
                  One item for every pixel is really pretty bad. The design and performance-wise.

                  I once thought about using the method you mentioned, but once I used the image watch plugin to view pixel values, I gave up that idea.Now I have used their combination. Use pixmap when you don't need to view pixel values, and use pixelItem when you need to view pixel values.
                  Simply switch them by whether or not to display them。There is still some work to make it work smoothly now。
                  Sincerely thank you for your reply

                  P 1 Reply Last reply 2 Apr 2024, 18:06
                  0
                  • W wujie
                    2 Apr 2024, 12:35

                    @Pl45m4 said in Reproduce image watch:

                    This is also possible when having a QImage or QPixmap on a widget, or even the whole image as a single QGraphicsItem (QGraphicsPixmapItem).
                    One item for every pixel is really pretty bad. The design and performance-wise.

                    I once thought about using the method you mentioned, but once I used the image watch plugin to view pixel values, I gave up that idea.Now I have used their combination. Use pixmap when you don't need to view pixel values, and use pixelItem when you need to view pixel values.
                    Simply switch them by whether or not to display them。There is still some work to make it work smoothly now。
                    Sincerely thank you for your reply

                    P Offline
                    P Offline
                    Pl45m4
                    wrote on 2 Apr 2024, 18:06 last edited by
                    #9

                    @wujie said in Reproduce image watch:

                    Simply switch them by whether or not to display them

                    But this doesn't change that it will we slow and probably laggy, when you show the image as 1920x1080 graphics item "pixels".
                    As my example shows, you can see the pixel values when using QImage.
                    If you want that "overlay" like in OpenCV where you see the RGB value in place on top of each pixel, I think you can rebuild that in Qt as well.
                    There is no need to create "pixel"-QGraphicsItems


                    If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                    ~E. W. Dijkstra

                    C 1 Reply Last reply 2 Apr 2024, 18:34
                    0
                    • P Pl45m4
                      2 Apr 2024, 18:06

                      @wujie said in Reproduce image watch:

                      Simply switch them by whether or not to display them

                      But this doesn't change that it will we slow and probably laggy, when you show the image as 1920x1080 graphics item "pixels".
                      As my example shows, you can see the pixel values when using QImage.
                      If you want that "overlay" like in OpenCV where you see the RGB value in place on top of each pixel, I think you can rebuild that in Qt as well.
                      There is no need to create "pixel"-QGraphicsItems

                      C Offline
                      C Offline
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on 2 Apr 2024, 18:34 last edited by
                      #10

                      @Pl45m4 Just display it in a QLabel, catch the mouse move events and translate them to the appropriate row/column of the image.

                      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                      Visit the Qt Academy at https://academy.qt.io/catalog

                      P 1 Reply Last reply 2 Apr 2024, 19:00
                      0
                      • C Christian Ehrlicher
                        2 Apr 2024, 18:34

                        @Pl45m4 Just display it in a QLabel, catch the mouse move events and translate them to the appropriate row/column of the image.

                        P Offline
                        P Offline
                        Pl45m4
                        wrote on 2 Apr 2024, 19:00 last edited by
                        #11

                        @Christian-Ehrlicher

                        Not my topic ;-)
                        I did that here, but OP still wants to create pixel graphic items at some point...


                        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                        ~E. W. Dijkstra

                        1 Reply Last reply
                        0

                        6/11

                        2 Apr 2024, 01:10

                        • Login

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