如何显示2D numpy.ndarray作为特定QGraphicsView的像素值集合?
问题描述:
如何在QGraphicsView
上显示2D numpy.ndarray
作为像素值的集合?如果我不想制作GUI,通常会在此处使用pylab.imshow()
。如何显示2D numpy.ndarray作为特定QGraphicsView的像素值集合?
frame = array([[ 56., 57., 58., ..., 58., 58., 58.],
[ 52., 58., 58., ..., 56., 57., 59.],
[ 56., 55., 58., ..., 57., 57., 58.],
...,
[ 53., 55., 55., ..., 54., 54., 53.],
[ 54., 57., 56., ..., 53., 54., 59.],
[ 55., 57., 54., ..., 56., 58., 57.]])
我尝试:
scene = QGraphicsScene(self)
scene.addPixmap(QPixmap.fromImage(qimage2ndarray.array2qimage(frame)))
view = self.graphicsView(scene, self) # Error from this line
self.graphicsView = QtGui.QGraphicsView(scene, self)
view.show()
TypeError: 'QGraphicsView' object is not callable
。我想特别将场景添加到由QT Designer生成的名为graphicsView
的QGraphicsView
。如果我有以下
view = QtGui.QGraphicsView(scene, self)
然后图像显示更换导致错误的路线,但在QMainWindow
对我的其他部件的顶部左上角。如何限制放置到特定的QGraphicsView
?
答
我周围玩发现这种极简的解决方案:
scene = QGraphicsScene(self)
scene.addPixmap(QPixmap.fromImage(qimage2ndarray.array2qimage(frame)))
self.graphicsView.setScene(scene)
可能与此相同的问题吗? http://stackoverflow.com/questions/9794019/convert-numpy-array-to-pyside-qpixmap – DavidG
哇。看看我2小时的搜索历史记录,我从来没有使用'numpy',只有'矩阵/数组到QGraphicsView“和变体。无论如何,我修改了我的问题。取得了进展,但仍然停滞不前。 – Frikster