forked from raspberrypi/picamera2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp_capture2.py
More file actions
executable file
·56 lines (40 loc) · 1.49 KB
/
app_capture2.py
File metadata and controls
executable file
·56 lines (40 loc) · 1.49 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
#!/usr/bin/python3
# This example is essentially the same as app_capture.py, however here
# we use the Qt signal/slot mechanism to get a callback (capture_done)
# when the capture, that is running asynchronously, is finished.
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import *
from picamera2.previews.q_gl_picamera2 import *
from picamera2.picamera2 import *
def request_callback(request):
label.setText(''.join("{}: {}\n".format(k, v) for k, v in request.get_metadata().items()))
picam2 = Picamera2()
picam2.request_callback = request_callback
picam2.configure(picam2.preview_configuration(main={"size": (800, 600)}))
app = QApplication([])
def on_button_clicked():
button.setEnabled(False)
cfg = picam2.still_configuration()
picam2.switch_mode_and_capture_file(cfg, "test.jpg", wait=False, signal_function=qpicamera2.signal_done)
def capture_done():
button.setEnabled(True)
qpicamera2 = QGlPicamera2(picam2, width=800, height=600)
button = QPushButton("Click to capture JPEG")
label = QLabel()
window = QWidget()
qpicamera2.done_signal.connect(capture_done)
button.clicked.connect(on_button_clicked)
label.setFixedWidth(400)
label.setAlignment(QtCore.Qt.AlignTop)
layout_h = QHBoxLayout()
layout_v = QVBoxLayout()
layout_v.addWidget(label)
layout_v.addWidget(button)
layout_h.addWidget(qpicamera2, 80)
layout_h.addLayout(layout_v, 20)
window.setWindowTitle("Qt Picamera2 App")
window.resize(1200, 600)
window.setLayout(layout_h)
picam2.start()
window.show()
app.exec()