-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinputmonitor_ui.py
More file actions
100 lines (86 loc) · 2.96 KB
/
inputmonitor_ui.py
File metadata and controls
100 lines (86 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import os
import sys
import cv2
from PyQt5 import QtWidgets, QtCore, QtGui
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
# # UI Files
# from ui import inputmonitor
# class Thread(QThread):
# changePixmap = pyqtSignal(QImage)
# def run(self):
# cap = cv2.VideoCapture(0)
# while True:
# ret, frame = cap.read()
# # rgbImage = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
# h, w, ch = frame.shape
# bytesPerLine = ch * w
# cv2.imshow('a', frame)
# convertToQtFormat = QtGui.QImage(frame.data, w, h, bytesPerLine, QImage.Format_RGB888)
# p = convertToQtFormat.scaled(640, 480, Qt.KeepAspectRatio)
# self.changePixmap.emit(p)
# class InputMonitor(inputmonitor.Ui_MainWindow ,QMainWindow):
# def __init__(self):
# super(InputMonitor, self).__init__()
# MainWindow = QtWidgets.QMainWindow()
# self.setupUi(MainWindow)
# self.initUI()
# MainWindow.show()
# sys.exit(app.exec_())
# @pyqtSlot(QImage)
# def setImage(self, image):
# self.label.setPixmap(QPixmap.fromImage(image))
# def initUI(self):
# th = Thread(self)
# th.changePixmap.connect(self.setImage)
# th.start()
# if __name__ == "__main__":
# import sys
# app = QtWidgets.QApplication(sys.argv)
# MainWindow = QtWidgets.QMainWindow()
# ui = InputMonitor()
# ui.setupUi(MainWindow)
# MainWindow.show()
# sys.exit(app.exec_())
class Thread(QThread):
changePixmap = pyqtSignal(QImage)
def run(self):
cap = cv2.VideoCapture(0)
while True:
ret, frame = cap.read()
if ret:
# https://stackoverflow.com/a/55468544/6622587
rgbImage = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
h, w, ch = rgbImage.shape
bytesPerLine = ch * w
convertToQtFormat = QtGui.QImage(rgbImage.data, w, h, bytesPerLine, QtGui.QImage.Format_RGB888)
p = convertToQtFormat.scaled(640, 480, Qt.KeepAspectRatio)
self.changePixmap.emit(p)
class App(QWidget):
def __init__(self):
super().__init__()
self.title = 'PyQt5 Video'
self.left = 100
self.top = 100
self.width = 640
self.height = 480
self.initUI()
@pyqtSlot(QImage)
def setImage(self, image):
self.label.setPixmap(QPixmap.fromImage(image))
def initUI(self):
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
self.resize(1800, 1200)
# create a label
self.label = QLabel(self)
self.label.move(280, 120)
self.label.resize(640, 480)
th = Thread(self)
th.changePixmap.connect(self.setImage)
th.start()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()
sys.exit(app.exec_())