美文网首页python
pyqt5中使用GraphicsView显示图片

pyqt5中使用GraphicsView显示图片

作者: ThompsonHen | 来源:发表于2020-05-08 00:04 被阅读0次

在自己写一个图像检索系统的时候,
遇到如何将查找到的目标图片在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

相关文章

网友评论

    本文标题:pyqt5中使用GraphicsView显示图片

    本文链接:https://www.haomeiwen.com/subject/miitnhtx.html