convertToQtFormat = QtGui.QImage(rgbImage.data, rgbImage.shape[1], rgbImage.shape[0], QImage.Format_RGB888)
#在这里可以对每帧图像进行处理,
image = convertToQtFormat.scaled(440, 330, Qt.KeepAspectRatio)
self.video.setPixmap(QPixmap.fromImage(image))
rgbImage.data 是 python图片数组数据
所有组件都可以通过 setPixmap(QPixmap.fromImage(image)) 设置背景图像
import sysfrom PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QApplication, QMainWindow
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(270, 180, 241, 101))
self.label.setText("")
self.label.setPixmap(QtGui.QPixmap(":/img/logo.png"))
self.label.setObjectName("label")
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
if __name__ == '__main__':import resource
# 导入添加的资源(根据实际情况填写文件名)
app = QApplication(sys.argv)
MainWindow = QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
设置icon
self.pushButton_9.setIcon(QtGui.QIcon(QtGui.QPixmap("./resources/setting.png")))
self.pushButton_9.setIconSize(QtCore.QSize(30,30))