Newer
Older
import sys
from PyQt5.QtWidgets import QApplication, QDialog, QLabel
from PyQt5.QtGui import QImage, QPixmap
from PyQt5.QtCore import QTimer
import cv2
self.video = cv2.VideoCapture(0)
self.initUI()
def initUI(self):
self.setWindowTitle('miniMOKE')
self.setGeometry(300, 300, 800, 600)
self.label = QLabel(self)
self.label.setGeometry(0, 0, 1920//4, 1080//4)
self.label.setScaledContents(True)
self.timer = QTimer(self)
self.timer.timeout.connect(self.show_frame)
self.timer.start(20)
def show_frame(self):
_, frame = self.video.read()
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
image = QImage(frame, frame.shape[1], frame.shape[0],
frame.strides[0], QImage.Format_RGB888)
self.label.setPixmap(QPixmap.fromImage(image))