我从OpenCV捕获视频。我希望它以32位显示在gui上,但它显示24位。我尝试将image2 = QtGui.QImage(img0.data, width, height, bpl, QtGui.QImage.Format_RGB888)
更改为image2 = QtGui.QImage(img0.data, width, height, bpl, QtGui.QImage.Format_RGB32)
显示消息错误QImage: out of memory, returning null image”
my video output like this 我不需要此输出,我需要它显示原始颜色。我如何解决这个问题?
注意:我使用PyQT4和OpenCV3库。
class MyDialog(QtGui.QMainWindow):
def __init__(self, parent=None):
super(MyDialog, self).__init__(parent)
"""self.buttonBox = QtGui.QDialogButtonBox(self)
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
self.textBrowser = QtGui.QTextBrowser(self)
self.textBrowser.append("This is a QTextBrowser!")
self.verticalLayout = QtGui.QVBoxLayout(self)
self.verticalLayout.addWidget(self.textBrowser)
self.verticalLayout.addWidget(self.buttonBox)"""
self.left = 700
self.top = 400
self.width = 1920
self.height = 1080
self.setWindowTitle('Sender')
self.setGeometry(self.left, self.top, self.width, self.height)
self.setFixedSize(1920,1080)
self.videoFrame = ImageWidget()
self.setCentralWidget(self.videoFrame)
self.timer = QtCore.QTimer(self)
self.timer.timeout.connect(self.updateImage)
self.timer.start(30)
self.capture1 = cv2.VideoCapture(0)
def updateImage(self):
_, img0 = self.capture1.read()
height, width, bpc = img0.shape
bpl = bpc * width
image2 = QtGui.QImage(img0.data, width, height, bpl, QtGui.QImage.Format_RGB888)
pixmap2 = image2.scaled(300, 300, QtCore.Qt.KeepAspectRatio)
self.videoFrame2.setImage(pixmap2)
class ImageWidget(QtGui.QWidget):
def __init__(self,parent=None):
super(ImageWidget,self).__init__(parent)
self.image=None
def setImage(self,image):
self.image=image
sz=image.size()
self.setMinimumSize(sz)
self.update()
def paintEvent(self,event):
qp=QtGui.QPainter()
qp.begin(self)
if self.image:
qp.drawImage(QtCore.QPoint(150,150 ),self.image)
qp.end()