-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcamera_caps.py
executable file
·213 lines (172 loc) · 7.22 KB
/
camera_caps.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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/usr/bin/env python3
#
# Camera Capabilities
#
# Copyright (C) 2021-22 JetsonHacks ([email protected])
#
# MIT License
#
import sys
from dataclasses import dataclass
import gi
gi.require_version('Gst', '1.0')
gi.require_version('GstVideo', '1.0')
from gi.repository import Gst
from PyQt5.QtCore import QSize
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import (QApplication, QComboBox, QFrame, QHBoxLayout,
QLabel, QLayout, QLineEdit, QListWidget, QCheckBox,
QMainWindow, QPushButton, QScrollArea,
QSizePolicy, QVBoxLayout, QWidget)
from camera_caps_controller import Camera_Caps_Controller
from preview_window import PreviewWindow
@dataclass
class Camera_Caps_Config:
window_width: int = 640
window_height: int = 720
top_frame_height: int = 310
window_configs = Camera_Caps_Config()
class Camera_Caps_Window(QMainWindow):
def setup(self, controller):
self.ctrl_dict = {} # Holds control groups accessed by v4l2 control name
top_frame = self.setup_top_frame(controller)
self.setCentralWidget(top_frame)
self.setGeometry(100, 100, window_configs.window_width,
window_configs.window_height)
self.setWindowTitle('Camera Capabilities')
def setup_top_frame(self, controller):
main_frame = QFrame()
main_vbox = QVBoxLayout()
main_frame.setLayout(main_vbox)
top_frame = QFrame()
top_vbox = QVBoxLayout()
top_frame.setLayout(top_vbox)
top_frame.setMaximumHeight(window_configs.top_frame_height)
camera_box = QHBoxLayout()
camera_label = QLabel("Camera")
camera_label.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
camera_box.addWidget(camera_label)
self.camera_combo_box = QComboBox(self)
self.camera_combo_box.setSizePolicy(
QSizePolicy.Fixed, QSizePolicy.Fixed)
self.camera_combo_box.currentIndexChanged.connect(
controller.on_camera_box_changed)
camera_box.addWidget(self.camera_combo_box)
camera_box.addStretch()
top_vbox.addLayout(camera_box)
self.driver_label = QLabel("Driver")
self.bus_label = QLabel("Bus")
self.capabilities_label = QLabel("Capabilities")
self.device_capabilities_label = QLabel("Device Caps")
for label in [self.bus_label, self.driver_label, self.capabilities_label, self.device_capabilities_label]:
top_vbox.addWidget(label)
main_vbox.addWidget(top_frame)
middle_frame = self.setup_middle_frame(controller)
top_vbox.addWidget(middle_frame)
preview_frame = self.setup_preview_frame(controller)
top_vbox.addWidget(preview_frame)
self.bottom_frame = self.setup_control_menu_frame(controller)
main_vbox.addWidget(self.bottom_frame)
return main_frame
def setup_middle_frame(self, controller):
middle_frame = QFrame()
middle_hbox = QHBoxLayout()
middle_frame.setLayout(middle_hbox)
# List of pixel formats
vbox = QVBoxLayout()
vbox.addWidget(QLabel("Pixel Format"))
self.pixel_format_list = QListWidget()
self.pixel_format_list.setMinimumWidth(280)
self.pixel_format_list.itemClicked.connect(
controller.on_pixel_format_list_clicked)
vbox.addWidget(self.pixel_format_list)
# middle_hbox.addWidget(self.pixel_format_list)
middle_hbox.addLayout(vbox)
# Image Size list
vbox = QVBoxLayout()
vbox.addWidget(QLabel("Image Size"))
self.image_size_list = QListWidget()
self.image_size_list.setMinimumWidth(280)
self.image_size_list.itemClicked.connect(
controller.on_image_size_list_clicked)
vbox.addWidget(self.image_size_list)
middle_hbox.addLayout(vbox)
# FPS list
vbox = QVBoxLayout()
vbox.addWidget(QLabel("Frame Duration"))
self.fps_list = QListWidget()
self.fps_list.setMinimumWidth(280)
self.fps_list.itemClicked.connect(controller.on_fps_list_clicked)
vbox.addWidget(self.fps_list)
middle_hbox.addLayout(vbox)
return middle_frame
def setup_preview_frame(self, controller):
self.preview = QWidget()
preview_hbox = QHBoxLayout()
self.preview.setLayout(preview_hbox)
self.line_edit = QLineEdit()
# self.line_edit.setText(
# "v4l2src device=/dev/video4 ! video/x-raw, width=640, height=480, framerate=30/1 ! xvimagesink")
self.line_edit.setText("")
preview_hbox.addWidget(self.line_edit)
self.copy_button = QPushButton('')
self.copy_button.line_edit = self.line_edit
self.copy_button.setIcon(QIcon('baseline_content_copy_black_24dp.png'))
self.copy_button.setIconSize(QSize(24, 24))
self.copy_button.clicked.connect(controller.copy_button_clicked)
preview_hbox.addWidget(self.copy_button)
self.preview_button = QPushButton('')
self.preview_button.line_edit = self.line_edit
self.preview_button.setIcon(QIcon('baseline_preview_black_24dp.png'))
self.preview_button.setIconSize(QSize(24, 24))
self.preview_button.clicked.connect(controller.preview_button_clicked)
preview_hbox.addWidget(self.preview_button)
self.sync_flag_checkbox = QCheckBox('Synchronize Video')
self.sync_flag_checkbox.clicked.connect(controller.on_sync_flag_checkbox_clicked)
preview_hbox.addWidget(self.sync_flag_checkbox)
return self.preview
def setup_control_menu_frame(self, controller):
self.scroll = QScrollArea()
self.scroll.setWidgetResizable(True)
# scroll_vbox = QVBoxLayout()
# self.scroll.setLayout(scroll_vbox)
self.control_menu_frame = QFrame()
control_menu_vbox = QVBoxLayout()
self.control_menu_frame.setLayout(control_menu_vbox)
self.scroll.setWidget(self.control_menu_frame)
# return self.control_menu_frame
return self.scroll
def clear_layout(self, layout: QLayout):
self.ctrl_dict = {} # Clear out previous ctrl groups
child = layout.takeAt(0)
while child is not None:
if child.layout() is not None:
self.clear_layout(child.layout())
elif child.widget() is not None:
layout.removeWidget(child.widget())
child.widget().setParent(None)
child = layout.takeAt(0)
def create_preview_window(self):
preview_window = PreviewWindow()
preview_window.setup()
return preview_window
def closeEvent(self, event):
# Closing this window terminates the application
for window in self.preview_windows:
window.app_closing = True
window.close()
def main():
Gst.init(None)
app = QApplication(sys.argv)
window = Camera_Caps_Window()
window.preview_windows = window.create_preview_window()
controller = Camera_Caps_Controller(window)
controller.setup()
"""
def quitting_app():
controller.app_quitting()
"""
app.aboutToQuit.connect(controller.app_quitting)
sys.exit(app.exec_())
if __name__ == '__main__':
main()