Skip to content

Commit 17c68ce

Browse files
Fixed UVC Cams after breaking them again :P
1 parent 15fd99c commit 17c68ce

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

BabbleApp/camera.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def run(self):
8383
return
8484
should_push = True
8585
# If things aren't open, retry until they are. Don't let read requests come in any earlier
86-
# than this, otherwise we can deadlock ourselves.
86+
# than this, otherwise we can deadlock (valve reference) ourselves.
8787
if (
8888
self.config.capture_source is not None and self.config.capture_source != ""
8989
):
@@ -174,7 +174,7 @@ def get_cv2_camera_picture(self, should_push):
174174
#self.bps = image.nbytes
175175
if should_push:
176176
self.push_image_to_queue(image, frame_number, self.fps)
177-
except:
177+
except Exception as e:
178178
print(
179179
f"{Fore.YELLOW}[WARN] Capture source problem, assuming camera disconnected, waiting for reconnect.{Fore.RESET}")
180180
self.camera_status = CameraState.DISCONNECTED

BabbleApp/camera_widget.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def __init__(self, widget_id: Tab, main_config: BabbleConfig, osc_queue: Queue):
3535
self.gui_vertical_flip = f"-VERTICALFLIP{widget_id}-"
3636
self.gui_horizontal_flip = f"-HORIZONTALFLIP{widget_id}-"
3737
self.use_calibration = f"-USECALIBRATION{widget_id}-"
38+
self.gui_refresh_button = f"-REFRESHCAMLIST{widget_id}-"
3839
self.osc_queue = osc_queue
3940
self.main_config = main_config
4041
self.cam_id = widget_id
@@ -165,10 +166,11 @@ def __init__(self, widget_id: Tab, main_config: BabbleConfig, osc_queue: Queue):
165166
self.widget_layout = [
166167
[
167168
sg.Text("Camera Address", background_color='#424042'),
168-
sg.InputCombo(self.camera_list, default_value=self.config.capture_source,
169+
sg.InputCombo(values=self.camera_list, default_value=self.config.capture_source,
169170
key=self.gui_camera_addr,
170171
tooltip="Enter the IP address or UVC port of your camera. (Include the 'http://')",
171-
enable_events=True)
172+
enable_events=True),
173+
sg.Button("Refresh List", key=self.gui_refresh_button, button_color='#539e8a')
172174
],
173175
[
174176
sg.Button("Save and Restart Tracking", key=self.gui_save_tracking_button, button_color='#539e8a'),
@@ -244,14 +246,18 @@ def render(self, window, event, values):
244246
try:
245247
self.config.use_ffmpeg = False
246248
# Try storing ints as ints, for those using wired cameras.
247-
if value not in self.camera_list:
248-
self.config.capture_source = value
249-
else:
249+
#if value not in self.camera_list:
250+
# self.config.capture_source = value
250251
#if "COM" not in value:
251-
ports = ("COM", "/dev/tty")
252-
if any(x in str(self.config.capture_source) for x in ports):
252+
ports = ("COM", "/dev/tty")
253+
if any(x in str(value) for x in ports):
254+
self.config.capture_source = value
255+
else:
256+
cam = get_camera_index_by_name(value) # Set capture_source to the UVC index. Otherwise treat value like an ipcam if we return none
257+
if cam != None:
253258
self.config.capture_source = get_camera_index_by_name(value)
254-
else: self.config.capture_source = value
259+
else:
260+
self.config.capture_source = value
255261
except ValueError:
256262
if value == "":
257263
self.config.capture_source = None
@@ -273,8 +279,6 @@ def render(self, window, event, values):
273279

274280
changed = True
275281

276-
277-
278282
if self.config.rotation_angle != values[self.gui_rotation_slider]:
279283
self.config.rotation_angle = int(values[self.gui_rotation_slider])
280284
changed = True
@@ -330,6 +334,13 @@ def render(self, window, event, values):
330334
self.x0, self.y0 = values[self.gui_roi_selection]
331335
self.x1, self.y1 = values[self.gui_roi_selection]
332336

337+
if (event == self.gui_refresh_button):
338+
print("Refreshed Cameralist")
339+
self.camera_list = list_camera_names()
340+
print(self.camera_list)
341+
window[self.gui_camera_addr].update(values=self.camera_list)
342+
343+
333344
if event == self.gui_restart_calibration:
334345
self.babble_cnn.calibration_frame_counter = 1500
335346
PlaySound('Audio/start.wav', SND_FILENAME | SND_ASYNC)

0 commit comments

Comments
 (0)