forked from raspberrypi/picamera2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qt_preview.py
38 lines (32 loc) · 1.18 KB
/
qt_preview.py
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
import picamera2
import threading
import atexit
class QtPreview:
def thread_func(self, picam2, width, height):
# Running Qt in a thread other than the main thread is a bit tricky...
from q_picamera2 import QApplication, QPicamera2
self.app = QApplication([])
self.size = (width, height)
self.qpicamera2 = QPicamera2(picam2, width=width, height=height)
self.qpicamera2.setWindowTitle("QtPreview")
self.qpicamera2.show()
picam2.asynchronous = True
atexit.register(self.stop)
self.event.set()
self.app.exec()
atexit.unregister(self.stop)
self.qpicamera2.picamera2.asynchronous = False
del self.qpicamera2.label
del self.qpicamera2.camera_notifier
del self.qpicamera2
del self.app
def __init__(self, picam2, width=640, height=480):
self.event = threading.Event()
self.thread = threading.Thread(target=self.thread_func, args=(picam2, width, height))
self.thread.setDaemon(True)
self.thread.start()
self.event.wait()
def stop(self):
if hasattr(self, "app"):
self.app.quit()
self.thread.join()