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 ):
@@ -43,6 +41,7 @@ def __init__(self, widget_id: Tab, main_config: BabbleConfig, osc_queue: Queue):
43
41
self .settings_config = main_config .settings
44
42
self .config = main_config .cam
45
43
self .settings = main_config .settings
44
+ self .camera_list = list_camera_names ()
46
45
self .maybe_image = None
47
46
if self .cam_id == Tab .CAM :
48
47
self .config = main_config .cam
@@ -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 (
@@ -145,7 +146,7 @@ def __init__(self, widget_id: Tab, main_config: BabbleConfig, osc_queue: Queue):
145
146
default = self .config .gui_vertical_flip ,
146
147
key = self .gui_vertical_flip ,
147
148
background_color = '#424042' ,
148
- tooltip = "Vertically flip camera feed." ,
149
+ tooltip = "Vertically flip camera feed." ,
149
150
),
150
151
sg .Checkbox (
151
152
"Horizontal Flip:" ,
@@ -164,14 +165,19 @@ def __init__(self, widget_id: Tab, main_config: BabbleConfig, osc_queue: Queue):
164
165
self .widget_layout = [
165
166
[
166
167
sg .Text ("Camera Address" , background_color = '#424042' ),
167
- 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://')" ,),
168
+ sg .InputCombo (self .camera_list , default_value = self .config .capture_source ,
169
+ key = self .gui_camera_addr ,
170
+ tooltip = "Enter the IP address or UVC port of your camera. (Include the 'http://')" ,
171
+ enable_events = True )
168
172
],
169
173
[
170
174
sg .Button ("Save and Restart Tracking" , key = self .gui_save_tracking_button , button_color = '#539e8a' ),
171
175
],
172
176
[
173
- sg .Button ("Tracking Mode" , key = self .gui_tracking_button , button_color = '#539e8a' , tooltip = "Go here to track your mouth." ,),
174
- sg .Button ("Cropping Mode" , key = self .gui_roi_button , button_color = '#539e8a' , tooltip = "Go here to crop out your mouth." ,),
177
+ sg .Button ("Tracking Mode" , key = self .gui_tracking_button , button_color = '#539e8a' ,
178
+ tooltip = "Go here to track your mouth." , ),
179
+ sg .Button ("Cropping Mode" , key = self .gui_roi_button , button_color = '#539e8a' ,
180
+ tooltip = "Go here to crop out your mouth." , ),
175
181
],
176
182
[
177
183
sg .Column (self .tracking_layout , key = self .gui_tracking_layout , background_color = '#424042' ),
@@ -230,25 +236,41 @@ def render(self, window, event, values):
230
236
changed = False
231
237
# If anything has changed in our configuration settings, change/update those.
232
238
if (
233
- event == self .gui_save_tracking_button
234
- and values [self .gui_camera_addr ] != self .config .capture_source
239
+ event == self .gui_save_tracking_button
240
+ and values [self .gui_camera_addr ] != self .config .capture_source
235
241
):
236
- print ("\033 [94m[INFO] New value: {}\033 [0m" .format (values [self .gui_camera_addr ]))
242
+ value = values [self .gui_camera_addr ]
243
+ print ("\033 [94m[INFO] New value: {}\033 [0m" .format (value ))
237
244
try :
245
+ self .config .use_ffmpeg = False
238
246
# Try storing ints as ints, for those using wired cameras.
239
- self .config .capture_source = int (values [self .gui_camera_addr ])
247
+ if value not in self .camera_list :
248
+ self .config .capture_source = int (value )
249
+ else :
250
+ self .config .capture_source = value
240
251
except ValueError :
241
- if values [ self . gui_camera_addr ] == "" :
252
+ if value == "" :
242
253
self .config .capture_source = None
243
254
else :
244
- 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 ]: # If http is not in camera address, add it.
245
- self .config .capture_source = f"http://{ values [self .gui_camera_addr ]} /"
246
- else :
247
- self .config .capture_source = values [self .gui_camera_addr ]
255
+ # If http is not in camera address, add it.
256
+ self .config .capture_source = value
257
+
258
+ if "udp" in value :
259
+ self .config .use_ffmpeg = True
260
+ elif (
261
+ "http" not in value
262
+ and ".mp4" not in value
263
+ and "udp" not in value
264
+ and "COM" not in value
265
+ and "/dev/tty" not in value
266
+ and value not in self .camera_list
267
+ ): # If http is not in camera address, add it.
268
+ self .config .capture_source = f"http://{ values [self .gui_camera_addr ]} /"
269
+
248
270
changed = True
249
271
250
272
251
-
273
+
252
274
if self .config .rotation_angle != values [self .gui_rotation_slider ]:
253
275
self .config .rotation_angle = int (values [self .gui_rotation_slider ])
254
276
changed = True
@@ -287,9 +309,9 @@ def render(self, window, event, values):
287
309
# Event for mouse button up in ROI mode
288
310
self .is_mouse_up = True
289
311
if self .x1 < 0 :
290
- self .x1 = 0
312
+ self .x1 = 0
291
313
if self .y1 < 0 :
292
- self .y1 = 0
314
+ self .y1 = 0
293
315
if abs (self .x0 - self .x1 ) != 0 and abs (self .y0 - self .y1 ) != 0 :
294
316
self .config .roi_window_x = min ([self .x0 , self .x1 ])
295
317
self .config .roi_window_y = min ([self .y0 , self .y1 ])
@@ -334,7 +356,7 @@ def render(self, window, event, values):
334
356
window [self .gui_tracking_bps ].update (self ._movavg_bps (self .camera .bps ))
335
357
336
358
if self .in_roi_mode :
337
- try :
359
+ try :
338
360
if self .roi_queue .empty ():
339
361
self .capture_event .set ()
340
362
maybe_image = self .roi_queue .get (block = False )
@@ -364,7 +386,6 @@ def render(self, window, event, values):
364
386
imgbytes = cv2 .imencode (".ppm" , maybe_image )[1 ].tobytes ()
365
387
window [self .gui_tracking_image ].update (data = imgbytes )
366
388
367
-
368
389
# Relay information to OSC
369
390
if cam_info .info_type != CamInfoOrigin .FAILURE :
370
391
self .osc_queue .put ((self .cam_id , cam_info ))
0 commit comments