Skip to content

Commit d6bca7c

Browse files
List serial cams and fix bugs
1 parent 6c1f085 commit d6bca7c

File tree

5 files changed

+44
-24
lines changed

5 files changed

+44
-24
lines changed

BabbleApp/babble_processor.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def __init__(
6868
self.current_image_gray = None
6969
self.current_frame_number = None
7070
self.current_fps = None
71+
self.FRAMESIZE = [0,0,1]
7172

7273
self.calibration_frame_counter = None
7374

@@ -129,6 +130,7 @@ def capture_crop_rotate_image(self):
129130

130131
try:
131132
# Get frame from capture source, crop to ROI
133+
self.FRAMESIZE = self.current_image.shape
132134
self.current_image = self.current_image[
133135
int(self.config.roi_window_y): int(
134136
self.config.roi_window_y + self.config.roi_window_h
@@ -238,3 +240,5 @@ def run(self):
238240
#print(self.output)
239241
self.output_images_and_update(CamInfo(self.current_algo, self.output))
240242

243+
def get_framesize(self):
244+
return self.FRAMESIZE

BabbleApp/babbleapp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def main():
262262
config.save()
263263

264264
elif values[CALIB_SETTINGS_RADIO_NAME] and config.cam_display_id != Tab.CALIBRATION:
265-
cams[0].stop()
265+
cams[0].start() # Allow tracking to continue in calibration tab
266266
settings[0].stop()
267267
settings[1].stop()
268268
settings[2].start()

BabbleApp/camera.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def __init__(
6666
self.prevft = 0
6767
self.newft = 0
6868
self.fl = [0]
69+
self.FRAME_SIZE = [0,0]
6970

7071
self.error_message = f"{Fore.YELLOW}[WARN] Capture source {{}} not found, retrying...{Fore.RESET}"
7172

@@ -141,6 +142,7 @@ def run(self):
141142
if any(x in str(self.config.capture_source) for x in ports):
142143
self.get_serial_camera_picture(should_push)
143144
else:
145+
self.__del__()
144146
self.get_cv2_camera_picture(should_push)
145147
if not should_push:
146148
# if we get all the way down here, consider ourselves connected
@@ -152,6 +154,7 @@ def get_cv2_camera_picture(self, should_push):
152154
if not ret:
153155
self.cv2_camera.set(cv2.CAP_PROP_POS_FRAMES, 0)
154156
raise RuntimeError("Problem while getting frame")
157+
self.FRAME_SIZE = image.shape
155158
frame_number = self.cv2_camera.get(cv2.CAP_PROP_POS_FRAMES)
156159
# Calculate the fps.
157160
yeah = time.time()

BabbleApp/camera_widget.py

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from babble_processor import BabbleProcessor, CamInfoOrigin
99
from camera import Camera, CameraState
1010
from config import BabbleConfig
11-
from landmark_processor import LandmarkProcessor
1211
from osc import Tab
1312
from utils.misc_utils import PlaySound, SND_FILENAME, SND_ASYNC, list_camera_names, get_camera_index_by_name
1413

@@ -68,16 +67,6 @@ def __init__(self, widget_id: Tab, main_config: BabbleConfig, osc_queue: Queue):
6867
self.cam_id,
6968
)
7069

71-
self.babble_landmark = LandmarkProcessor(
72-
self.config,
73-
self.settings_config,
74-
self.main_config,
75-
self.cancellation_event,
76-
self.capture_event,
77-
self.capture_queue,
78-
self.image_queue,
79-
self.cam_id,
80-
)
8170

8271
self.camera_status_queue = Queue(maxsize=2)
8372
self.camera = Camera(
@@ -92,7 +81,7 @@ def __init__(self, widget_id: Tab, main_config: BabbleConfig, osc_queue: Queue):
9281

9382
self.roi_layout = [
9483
[
95-
sg.Button("Auto ROI", key=self.gui_autoroi, button_color='#539e8a', tooltip="Automatically set ROI", ),
84+
sg.Button("Select Entire Frame", key=self.gui_autoroi, button_color='#539e8a', tooltip="Automatically set ROI", ),
9685
],
9786
[
9887
sg.Graph(
@@ -122,9 +111,10 @@ def __init__(self, widget_id: Tab, main_config: BabbleConfig, osc_queue: Queue):
122111
],
123112
[
124113
sg.Button("Start Calibration", key=self.gui_restart_calibration, button_color='#539e8a',
125-
tooltip="Start calibration. Look all arround to all extreams without blinking until sound is heard.", ),
114+
tooltip="Neutural Calibration: Hold a relaxed face, press [Start Calibration] and then press [Stop Calibraion]. \nFull Calibration: Press [Start Calibration] and make as many face movements as you can until it switches back to tracking mode or press [Stop Calibration]", disabled=True),
115+
126116
sg.Button("Stop Calibration", key=self.gui_stop_calibration, button_color='#539e8a',
127-
tooltip="Stop calibration manualy.", ),
117+
tooltip="Stop calibration manualy.", disabled=True),
128118
],
129119
[
130120
sg.Checkbox(
@@ -133,6 +123,7 @@ def __init__(self, widget_id: Tab, main_config: BabbleConfig, osc_queue: Queue):
133123
key=self.use_calibration,
134124
background_color='#424042',
135125
tooltip="Checked = Calibrated model output. Unchecked = Raw model output",
126+
enable_events=True
136127
),
137128
],
138129
[
@@ -197,7 +188,7 @@ def __init__(self, widget_id: Tab, main_config: BabbleConfig, osc_queue: Queue):
197188

198189
def _movavg_fps(self, next_fps):
199190
self.movavg_fps_queue.append(next_fps)
200-
fps = round(sum(self.movavg_fps_queue) / len(self.movavg_fps_queue))
191+
fps = round(sum(self.movavg_fps_queue) / len(self.movavg_fps_queue))
201192
millisec = round((1 / fps if fps else 0) * 1000)
202193
return f"{fps} Fps {millisec} ms"
203194

@@ -283,7 +274,6 @@ def render(self, window, event, values):
283274
self.config.rotation_angle = int(values[self.gui_rotation_slider])
284275
changed = True
285276

286-
#print(self.config.gui_vertical_flip)
287277
if self.config.gui_vertical_flip != values[self.gui_vertical_flip]:
288278
self.config.gui_vertical_flip = values[self.gui_vertical_flip]
289279
changed = True
@@ -313,6 +303,17 @@ def render(self, window, event, values):
313303
window[self.gui_roi_layout].update(visible=True)
314304
window[self.gui_tracking_layout].update(visible=False)
315305

306+
if event == self.use_calibration:
307+
print("toggle event")
308+
if self.settings_config.use_calibration == True:
309+
window[self.gui_restart_calibration].update(disabled = False)
310+
window[self.gui_stop_calibration].update(disabled = False)
311+
print("Enabled")
312+
else:
313+
window[self.gui_restart_calibration].update(disabled = True)
314+
window[self.gui_stop_calibration].update(disabled = True)
315+
print("Disabled")
316+
316317
if event == "{}+UP".format(self.gui_roi_selection):
317318
# Event for mouse button up in ROI mode
318319
self.is_mouse_up = True
@@ -334,19 +335,30 @@ def render(self, window, event, values):
334335
self.x0, self.y0 = values[self.gui_roi_selection]
335336
self.x1, self.y1 = values[self.gui_roi_selection]
336337

338+
if event == self.gui_autoroi:
339+
print("Set ROI")
340+
output = self.babble_cnn.get_framesize()
341+
self.config.roi_window_x = 0
342+
self.config.roi_window_y = 0
343+
self.config.roi_window_w = output[0]
344+
self.config.roi_window_h = output[1]
345+
self.main_config.save()
346+
337347
if (event == self.gui_refresh_button):
338-
print("Refreshed Cameralist")
348+
print("\033[94m[INFO] Refreshed Camera List\033[0m")
339349
self.camera_list = list_camera_names()
340350
print(self.camera_list)
341351
window[self.gui_camera_addr].update(values=self.camera_list)
342352

343353

344354
if event == self.gui_restart_calibration:
345-
self.babble_cnn.calibration_frame_counter = 1500
346-
PlaySound('Audio/start.wav', SND_FILENAME | SND_ASYNC)
355+
if values[self.use_calibration] == True: # Don't start recording if the calibration filter is disabled.
356+
self.babble_cnn.calibration_frame_counter = 1500
357+
PlaySound('Audio/start.wav', SND_FILENAME | SND_ASYNC)
347358

348359
if event == self.gui_stop_calibration:
349-
self.babble_cnn.calibration_frame_counter = 0
360+
if self.babble_cnn.calibration_frame_counter != None: # Only assign the variable if we are in calibration mode.
361+
self.babble_cnn.calibration_frame_counter = 0
350362

351363
needs_roi_set = self.config.roi_window_h <= 0 or self.config.roi_window_w <= 0
352364

BabbleApp/utils/misc_utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,21 @@ def list_camera_names():
9090
if is_nt:
9191
# On Windows, use pygrabber to list devices
9292
cam_list = graph.get_input_devices()
93-
return cam_list
93+
return cam_list + list_serial_ports()
9494

9595
elif os_type == "Linux":
9696
# On Linux, return UVC device paths like '/dev/video0'
97-
return list_linux_uvc_devices()
97+
return list_linux_uvc_devices() + list_serial_ports()
9898

9999
elif os_type == "Darwin":
100100
# On macOS, fallback to OpenCV (device names aren't fetched)
101-
return list_cameras_opencv()
101+
return list_cameras_opencv() + list_serial_ports()
102102

103103
else:
104104
return ["Unsupported operating system"]
105105

106106
def list_serial_ports():
107+
print("DEBUG: Listed Serial Ports")
107108
""" Lists serial port names
108109
109110
:raises EnvironmentError:

0 commit comments

Comments
 (0)