如何使用openCV和pyqt5在QLabel中显示16位RGB tif图像?

时间:2020-10-04 17:18:55

标签: python opencv user-interface pyqt5

我是python编程的新手。目前,我正在开发一个程序,该程序需要使用openCV和pyqt5在QLabel中显示16位RGB tif图像。我尝试了QImage文档中所有可能的QImage格式选项,但似乎没有任何效果。我正在寻找解决此问题的方法,否则将不胜感激。 非常感谢

from PyQt5 import QtWidgets, QtGui, QtCore
import sys
import cv2
import numpy as np

path = "e:/python/Delta1.tif"

app = QtWidgets.QApplication(sys.argv)

input_image = cv2.imread(path,-1)
height, width, channels = input_image.shape
bytesPerLine = channels * width
qImg = QtGui.QImage(input_image.data, input_image.shape[1], input_image.shape[0], QtGui.QImage.Format_RGB16).rgbSwapped() 
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_())   

0 个答案:

没有答案