python

pyqt5中使用GraphicsView显示图片

2020-05-08  本文已影响0人  ThompsonHen

在自己写一个图像检索系统的时候,
遇到如何将查找到的目标图片在pyqt5的界面中展示出来的问题。
在问题解决后做了这个笔记。

 def show_selected_image(self, image):

        height = image.shape[0]
        width = image.shape[1]
        ratio = float(height / width)
        new_height = 300
        new_width =  int(300 / ratio)
        img = cv2.resize(image, (new_width, new_height))


        frame = QImage(img, new_width, new_height, QImage.Format_RGB888)
        pix = QPixmap.fromImage(frame)
        self.item = QGraphicsPixmapItem(pix)
        self.scene = QGraphicsScene()  # 创建场景
        self.scene.addItem(self.item)
        self.graphicsView.setScene(self.scene)
图像检索系统demo.png
上一篇 下一篇

猜你喜欢

热点阅读