使用opencv提取视频流中一帧图像

使用opencv提取视频流中一帧图像

MAIN,py文件

from PyQt5 import QtWidgets
from PyQt5.Qt import *
import cv2 as cv
from Qui_QImage_test import Ui_Win_1

def dis():
    print("dis")
    capture = cv.VideoCapture(0)
    
    #使用capture.read()提取视频流中的一帧
    net,img = capture.read()
    print(img.shape)

	#转换img图像为QImage
    qimg = QImage(img, img.shape[1], img.shape[0], QImage.Format_RGB888)
    print(img.shape[1], img.shape[0])
    qimg = QPixmap(qimg).scaled(img.shape[1], img.shape[0])
    ui.label.setPixmap(qimg)
    #label富文本显示图像,

if __name__ == '__main__':
    import sys

    app = QtWidgets.QApplication(sys.argv)
    Win_1 = QtWidgets.QWidget()
    ui = Ui_Win_1()

    ui.setupUi(Win_1)


    ui.PBT_1.clicked.connect(dis)


    Win_1.show()
    sys.exit(app.exec_())

界面ui文件Qui_QImage_test

from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_Win_1(object):
    def setupUi(self, Win_1):
        Win_1.setObjectName("Win_1")
        Win_1.resize(1058, 608)
        Win_1.setAutoFillBackground(True)
        Win_1.setStyleSheet("")
        self.PBT_1 = QtWidgets.QPushButton(Win_1)
        self.PBT_1.setGeometry(QtCore.QRect(810, 80, 91, 31))
        self.PBT_1.setObjectName("PBT_1")
        self.label = QtWidgets.QLabel(Win_1)
        self.label.setGeometry(QtCore.QRect(60, 70, 640, 480))
        self.label.setAutoFillBackground(False)
        self.label.setStyleSheet("background-color: rgb(255, 255, 127);")
        self.label.setObjectName("label")

        self.retranslateUi(Win_1)
        QtCore.QMetaObject.connectSlotsByName(Win_1)

    def retranslateUi(self, Win_1):
        _translate = QtCore.QCoreApplication.translate
        Win_1.setWindowTitle(_translate("Win_1", "Qimage_test"))
        self.PBT_1.setText(_translate("Win_1", "显示图像"))
        self.label.setText(_translate("Win_1", "TextLabel"))


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    Win_1 = QtWidgets.QWidget()
    ui = Ui_Win_1()
    ui.setupUi(Win_1)
    Win_1.show()
    sys.exit(app.exec_())

运行界面显示
使用opencv提取视频流中一帧图像_第1张图片

你可能感兴趣的:(opencv,python,ui)