【发布时间】:2019-07-17 14:24:31
【问题描述】:
我有一个名为 rgb_array 的具有 3 个通道 (RGB) 的矩阵数组。
我想用 PyQt 来显示。
根据stackoverflow中的一些(旧)帖子,我编写了以下代码(基于gym-minigrid)
from PyQt5.QtGui import QPixmap
from PyQt5.QtGui import QImage
from PyQt5.QtWidgets import QLabel
from PyQt5.QtWidgets import QMainWindow, QWidget
class Window(QMainWindow):
"""
Simple application window to render the environment into
"""
def __init__(self):
super().__init__()
# Image label to display the rendering
self.imgLabel = QLabel()
# Create a main widget for the window
mainWidget = QWidget(self)
self.setCentralWidget(mainWidget)
# Show the application window
self.show()
self.setFocus()
def setPixmap(self, pixmap):
self.imgLabel.setPixmap(pixmap)
rgb_array = ... # my image
height, width, _ = rgb_array.shape
bytes_per_line = 3 * width
qt_img = QImage(rgb_array.data, width, height, bytes_per_line, QImage.Format_RGB888)
pixmap = QPixmap.fromImage(qt_img)
window = Window()
window.setPixmap(pixmap)
但是每次我运行它时,我都会遇到分段错误。任何的想法 ?谢谢!
【问题讨论】:
标签: python-3.x pyqt5