2017-03-03 12 views
0

私は、numpy配列をpixmapに変換して、GUI内のラベルに表示しました。プログラムを実行すると、何らかの理由でGUIが終了します(エラーメッセージは表示されません)。PyQt - ラベルを使用して画像を表示する

height, width = input_image.shape 
bytesPerLine = 3 * width 
qImg = QtGui.QImage(input_image.data, width, height, bytesPerLine, QtGui.QImage.Format_RGB888) 
pixmap01 = QtGui.QPixmap.fromImage(qImg) 
self.pixmap_image = QtGui.QPixmap(pixmap01) 
self.ui.label_imageDisplay.setPixmap(self.pixmap_image) 
self.ui.label_imageDisplay.setAlignment(QtCore.Qt.AlignCenter) 
self.ui.label_imageDisplay.setScaledContents(True) 
self.ui.label_imageDisplay.setMinimumSize(1,1) 
self.ui.label_imageDisplay.show() 

答えて

3

これを試してみてください:

from PyQt5 import QtWidgets, QtGui, QtCore 

from scipy.ndimage import imread 
import sys 

app = QtWidgets.QApplication(sys.argv) 

input_image = imread({your filename}) 
height, width, channels = input_image.shape 
bytesPerLine = channels * width 
qImg = QtGui.QImage(input_image.data, width, height, bytesPerLine, QtGui.QImage.Format_RGB888) 
pixmap01 = QtGui.QPixmap.fromImage(qImg) 
pixmap_image = QtGui.QPixmap(pixmap01) 
label_imageDisplay = QtWidgets.QLabel() 
label_imageDisplay.setPixmap(pixmap_image) 
label_imageDisplay.setAlignment(QtCore.Qt.AlignCenter) 
label_imageDisplay.setScaledContents(True) 
label_imageDisplay.setMinimumSize(1,1) 
label_imageDisplay.show() 
sys.exit(app.exec_()) 

enter image description here

関連する問題