我从我的相机读取图像作为numpy的阵列。 我的目标是把它放在一个QWidget内从pyqt5并打印在我的主窗口GUI程序,但我发现了以下错误:
TypeError: QPixmap(): argument 1 has unexpected type 'numpy.ndarray'
下面是代码:
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from epics import PV
import numpy as np
class PanoramicGUI:
def __init__(self):
self.MainWindow = uic.loadUi('panoramicGUI.ui')
self.MainWindow.SavePositionButton. clicked.connect(self.save_image)
def save_image(self):
detectorData = PV("CAMERA:DATA")
self.data = detectorData.get()
self.data = np.array(self.data).reshape(2048,2048).astype(np.int32)
print(self.data)
img = PrintImage(QPixmap(self.data))
self.MainWindow.WidgetHV1X1.setLayout(QtWidgets.QVBoxLayout())
self.MainWindow.WidgetHV1X1.layout().addWidget(img)
class PrintImage(QWidget):
def __init__(self, pixmap, parent=None):
QWidget.__init__(self, parent=parent)
self.pixmap = pixmap
def paintEvent(self, event):
painter = QPainter(self)
painter.drawPixmap(self.rect(), self.pixmap)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
panoramic = PanoramicGUI()
panoramic.MainWindow.show()
app.exec_()
有人能帮我吗?
问候,
加布里埃尔。