1
- import PySimpleGUI as sg
2
- from config import BabbleConfig
3
- from config import BabbleSettingsConfig
4
1
from collections import deque
2
+ from queue import Queue , Empty
5
3
from threading import Event , Thread
4
+
5
+ import PySimpleGUI as sg
6
+
7
+ import cv2
6
8
from babble_processor import BabbleProcessor , CamInfoOrigin
7
- from landmark_processor import LandmarkProcessor
8
- from enum import Enum
9
- from queue import Queue , Empty
10
9
from camera import Camera , CameraState
10
+ from config import BabbleConfig
11
+ from landmark_processor import LandmarkProcessor
11
12
from osc import Tab
12
- import cv2
13
- import sys
14
- from utils .misc_utils import PlaySound ,SND_FILENAME ,SND_ASYNC
15
- import traceback
16
- import numpy as np
13
+ from utils .misc_utils import PlaySound , SND_FILENAME , SND_ASYNC , list_camera_names
14
+
17
15
18
16
class CameraWidget :
19
17
def __init__ (self , widget_id : Tab , main_config : BabbleConfig , osc_queue : Queue ):
@@ -44,6 +42,7 @@ def __init__(self, widget_id: Tab, main_config: BabbleConfig, osc_queue: Queue):
44
42
self .settings_config = main_config .settings
45
43
self .config = main_config .cam
46
44
self .settings = main_config .settings
45
+ self .camera_list = list_camera_names ()
47
46
if self .cam_id == Tab .CAM :
48
47
self .config = main_config .cam
49
48
else :
@@ -92,17 +91,17 @@ def __init__(self, widget_id: Tab, main_config: BabbleConfig, osc_queue: Queue):
92
91
93
92
self .roi_layout = [
94
93
[
95
- sg .Button ("Auto ROI" , key = self .gui_autoroi , button_color = '#539e8a' , tooltip = "Automatically set ROI" ,),
94
+ sg .Button ("Auto ROI" , key = self .gui_autoroi , button_color = '#539e8a' , tooltip = "Automatically set ROI" , ),
96
95
],
97
96
[
98
- sg .Graph (
99
- (640 , 480 ),
100
- (0 , 480 ),
101
- (640 , 0 ),
102
- key = self .gui_roi_selection ,
103
- drag_submits = True ,
104
- enable_events = True ,
105
- background_color = '#424042' ,
97
+ sg .Graph (
98
+ (640 , 480 ),
99
+ (0 , 480 ),
100
+ (640 , 0 ),
101
+ key = self .gui_roi_selection ,
102
+ drag_submits = True ,
103
+ enable_events = True ,
104
+ background_color = '#424042' ,
106
105
)
107
106
]
108
107
]
@@ -117,12 +116,14 @@ def __init__(self, widget_id: Tab, main_config: BabbleConfig, osc_queue: Queue):
117
116
orientation = "h" ,
118
117
key = self .gui_rotation_slider ,
119
118
background_color = '#424042' ,
120
- tooltip = "Adjust the rotation of your cameras, make them level." ,
119
+ tooltip = "Adjust the rotation of your cameras, make them level." ,
121
120
),
122
121
],
123
122
[
124
- sg .Button ("Start Calibration" , key = self .gui_restart_calibration , button_color = '#539e8a' , tooltip = "Start calibration. Look all arround to all extreams without blinking until sound is heard." ,),
125
- sg .Button ("Stop Calibration" , key = self .gui_stop_calibration , button_color = '#539e8a' , tooltip = "Stop calibration manualy." ,),
123
+ sg .Button ("Start Calibration" , key = self .gui_restart_calibration , button_color = '#539e8a' ,
124
+ tooltip = "Start calibration. Look all arround to all extreams without blinking until sound is heard." , ),
125
+ sg .Button ("Stop Calibration" , key = self .gui_stop_calibration , button_color = '#539e8a' ,
126
+ tooltip = "Stop calibration manualy." , ),
126
127
],
127
128
[
128
129
sg .Checkbox (
@@ -152,7 +153,7 @@ def __init__(self, widget_id: Tab, main_config: BabbleConfig, osc_queue: Queue):
152
153
default = self .config .gui_vertical_flip ,
153
154
key = self .gui_vertical_flip ,
154
155
background_color = '#424042' ,
155
- tooltip = "Vertically flip camera feed." ,
156
+ tooltip = "Vertically flip camera feed." ,
156
157
),
157
158
sg .Checkbox (
158
159
"Horizontal Flip:" ,
@@ -171,14 +172,19 @@ def __init__(self, widget_id: Tab, main_config: BabbleConfig, osc_queue: Queue):
171
172
self .widget_layout = [
172
173
[
173
174
sg .Text ("Camera Address" , background_color = '#424042' ),
174
- sg .InputText (self .config .capture_source , key = self .gui_camera_addr , tooltip = "Enter the IP address or UVC port of your camera. (Include the 'http://')" ,),
175
+ sg .InputCombo (self .camera_list , default_value = self .config .capture_source ,
176
+ key = self .gui_camera_addr ,
177
+ tooltip = "Enter the IP address or UVC port of your camera. (Include the 'http://')" ,
178
+ enable_events = True )
175
179
],
176
180
[
177
181
sg .Button ("Save and Restart Tracking" , key = self .gui_save_tracking_button , button_color = '#539e8a' ),
178
182
],
179
183
[
180
- sg .Button ("Tracking Mode" , key = self .gui_tracking_button , button_color = '#539e8a' , tooltip = "Go here to track your mouth." ,),
181
- sg .Button ("Cropping Mode" , key = self .gui_roi_button , button_color = '#539e8a' , tooltip = "Go here to crop out your mouth." ,),
184
+ sg .Button ("Tracking Mode" , key = self .gui_tracking_button , button_color = '#539e8a' ,
185
+ tooltip = "Go here to track your mouth." , ),
186
+ sg .Button ("Cropping Mode" , key = self .gui_roi_button , button_color = '#539e8a' ,
187
+ tooltip = "Go here to crop out your mouth." , ),
182
188
],
183
189
[
184
190
sg .Column (self .tracking_layout , key = self .gui_tracking_layout , background_color = '#424042' ),
@@ -237,28 +243,38 @@ def render(self, window, event, values):
237
243
changed = False
238
244
# If anything has changed in our configuration settings, change/update those.
239
245
if (
240
- event == self .gui_save_tracking_button
241
- and values [self .gui_camera_addr ] != self .config .capture_source
246
+ event == self .gui_save_tracking_button
247
+ and values [self .gui_camera_addr ] != self .config .capture_source
242
248
):
243
- print ("\033 [94m[INFO] New value: {}\033 [0m" .format (values [self .gui_camera_addr ]))
249
+ value = values [self .gui_camera_addr ]
250
+ print ("\033 [94m[INFO] New value: {}\033 [0m" .format (value ))
244
251
try :
245
252
self .config .use_ffmpeg = False
246
253
# Try storing ints as ints, for those using wired cameras.
247
- self .config .capture_source = int (values [self .gui_camera_addr ])
254
+ if value not in self .camera_list :
255
+ self .config .capture_source = int (value )
256
+ else :
257
+ self .config .capture_source = value
248
258
except ValueError :
249
- if values [ self . gui_camera_addr ] == "" :
259
+ if value == "" :
250
260
self .config .capture_source = None
251
261
else :
252
- if len (values [self .gui_camera_addr ]) > 5 and "http" not in values [self .gui_camera_addr ] and ".mp4" not in values [self .gui_camera_addr ] and "udp" not in values [self .gui_camera_addr ]: # If http is not in camera address, add it.
253
- self .config .capture_source = f"http://{ values [self .gui_camera_addr ]} /"
254
- elif "udp" in values [self .gui_camera_addr ]:
255
- self .config .use_ffmpeg = True
256
- self .config .capture_source = values [self .gui_camera_addr ]
257
- else :
258
- self .config .capture_source = values [self .gui_camera_addr ]
259
- changed = True
262
+ # If http is not in camera address, add it.
263
+ self .config .capture_source = value
260
264
265
+ if "udp" in value :
266
+ self .config .use_ffmpeg = True
267
+ elif (
268
+ "http" not in value
269
+ and ".mp4" not in value
270
+ and "udp" not in value
271
+ and "COM" not in value
272
+ and "/dev/tty" not in value
273
+ and value not in self .camera_list
274
+ ): # If http is not in camera address, add it.
275
+ self .config .capture_source = f"http://{ values [self .gui_camera_addr ]} /"
261
276
277
+ changed = True
262
278
263
279
if self .config .rotation_angle != values [self .gui_rotation_slider ]:
264
280
self .config .rotation_angle = int (values [self .gui_rotation_slider ])
@@ -302,9 +318,9 @@ def render(self, window, event, values):
302
318
# Event for mouse button up in ROI mode
303
319
self .is_mouse_up = True
304
320
if self .x1 < 0 :
305
- self .x1 = 0
321
+ self .x1 = 0
306
322
if self .y1 < 0 :
307
- self .y1 = 0
323
+ self .y1 = 0
308
324
if abs (self .x0 - self .x1 ) != 0 and abs (self .y0 - self .y1 ) != 0 :
309
325
self .config .roi_window_x = min ([self .x0 , self .x1 ])
310
326
self .config .roi_window_y = min ([self .y0 , self .y1 ])
@@ -370,7 +386,7 @@ def render(self, window, event, values):
370
386
window [self .gui_tracking_bps ].update (self ._movavg_bps (self .camera .bps ))
371
387
372
388
if self .in_roi_mode :
373
- try :
389
+ try :
374
390
if self .roi_queue .empty ():
375
391
self .capture_event .set ()
376
392
maybe_image = self .roi_queue .get (block = False )
@@ -399,7 +415,6 @@ def render(self, window, event, values):
399
415
imgbytes = cv2 .imencode (".ppm" , maybe_image )[1 ].tobytes ()
400
416
window [self .gui_tracking_image ].update (data = imgbytes )
401
417
402
-
403
418
# Relay information to OSC
404
419
if cam_info .info_type != CamInfoOrigin .FAILURE :
405
420
self .osc_queue .put ((self .cam_id , cam_info ))
0 commit comments