Reproduce image watch
-
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: -
@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
-
@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
-
@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
andQPixmap
classes -
@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
orQPixmap
on a widget, or even the whole image as a singleQGraphicsItem
(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:
The code is also in the topic some comments below my GIF.
I used a custom
QLabel
class and its built-insetPixmap
function.
Surely it can be optimized, but might be a good point to start with. -
@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 -
@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 usingQImage
.
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
-
@Pl45m4 Just display it in a QLabel, catch the mouse move events and translate them to the appropriate row/column of the image.
-
Not my topic ;-)
I did that here, but OP still wants to create pixel graphic items at some point...