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
|
import sys
import numpy as np
from PyQt6.QtWidgets import QApplication, QWidget, QLabel, QVBoxLayout
from PyQt6.QtGui import QPixmap
from PyQt6.QtCore import QTimer
from PIL import Image, ImageQt
fps = 30
h = 200
w = 200
c = 0
class EncoderWidget(QWidget):
def __init__(self):
super().__init__()
self.timer = QTimer(self)
self.timer.timeout.connect(self.update)
self.timer.start(1000 // fps)
self.label = QLabel(self)
layout = QVBoxLayout(self)
layout.addWidget(self.label)
layout.setContentsMargins(0, 0, 0, 0)
self.setLayout(layout)
self.showFullScreen()
def update(self):
global c
if c == 0:
array = np.random.randint(0, 256, (h, w, 3))
c = 1
else:
array = np.zeros((h, w, 3))
c = 0
img = Image.fromarray(array.astype(np.uint8), mode="RGB")
qt_img = ImageQt.ImageQt(img)
pixmap = QPixmap.fromImage(qt_img).scaled(self.size())
self.label.setPixmap(pixmap)
if __name__ == "__main__":
app = QApplication(sys.argv)
widget = EncoderWidget()
sys.exit(app.exec())
|