Skip to content
Snippets Groups Projects
ui.py 1.05 KiB
Newer Older
esarrey's avatar
esarrey committed
import sys
from PyQt5.QtWidgets import QApplication, QDialog, QLabel
from PyQt5.QtGui import QImage, QPixmap
from PyQt5.QtCore import QTimer
import cv2
esarrey's avatar
esarrey committed

esarrey's avatar
esarrey committed
class AppWindow(QDialog):
esarrey's avatar
esarrey committed
    def __init__(self):
        super().__init__()
esarrey's avatar
esarrey committed
        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))
esarrey's avatar
esarrey committed

if __name__ == "__main__":
esarrey's avatar
esarrey committed
    app = QApplication(sys.argv)
    window = AppWindow()
    window.show()
    sys.exit(app.exec_())