forked from raspberrypi/picamera2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
q_picamera2.py
31 lines (27 loc) · 1.19 KB
/
q_picamera2.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
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import pyqtSlot, QSocketNotifier
from PyQt5.QtWidgets import QWidget, QApplication, QLabel
from PIL import Image
from PIL.ImageQt import ImageQt
class QPicamera2(QWidget):
def __init__(self, picam2, parent=None, width=640, height=480):
super().__init__(parent=parent)
self.picamera2 = picam2
self.label = QLabel(self)
self.label.resize(width, height)
self.camera_notifier = QSocketNotifier(self.picamera2.camera_manager.efd,
QtCore.QSocketNotifier.Read,
self)
self.camera_notifier.activated.connect(self.handle_requests)
@pyqtSlot()
def handle_requests(self):
request = self.picamera2.process_requests()
if not request:
return
if self.picamera2.display_stream_name is not None:
size = self.label.size()
img = request.make_image(self.picamera2.display_stream_name, size.width(), size.height())
qim = ImageQt(img).copy()
pix = QtGui.QPixmap.fromImage(qim)
self.label.setPixmap(pix)
request.release()