将numpy数组转换为QImage

时间:2018-08-08 11:37:11

标签: python python-3.x numpy pyqt5 qgraphicsview

我想直接在Pyqt5中将numpy数组显示到QtGraphicsView。 但是numpy数组是独立的数组类型。
因此,我需要将numpy数组转换为Qimage。
但是我不知道如何将numpy数组转换为Qimage。

首先,看看我的代码的一部分

# initialize and capture image(image is saved register) 
# you can ignore this code line
spi.xfer2([0x28]) 
time.sleep(2)
spi.xfer2([0x78])
time.sleep(2)
spi.xfer2([0x88])
time.sleep(2)

# make lists and save imageData from sensor register to lists
ver = [0] * 10754
ver[0] = 0xf0
spi.xfer2([0xf4, 0x01])  # SPI Clock enable for memory access
spi.xfer2(ver)

# make numpy array and make matrix shape 
im = np.array(ver[2:])
image = np.transpose(im.reshape(-1, 56))

以下代码是处理程序

    def SaveImage(self):
    global image
    scene=QtWidgets.QGraphicsScene()

    qimage = QtGui.QImage(image)
    qimage.loadFromData(image)
    pimage= QPixmap.fromImage(image)
    scene.addPixmap(pimage)
    item= QtWidgets.QGraphicsPixmapItem(pimage)
    scene.addItem(item)
    self.graphicsView_SensoredImg.setScene(scene)

执行上述代码时生成错误。

TypeError: arguments did not match any overloaded call:
 QImage.loadFromData(str, str format = None): argument 1 has unexpected type 'numpy.ndarray'
QImage.loadFromData(QByteArray, str format = None): argument 1 has unexpected type 'numpy.ndarray'

0 个答案:

没有答案