Skip to content

Commit 9c62fd3

Browse files
Add CV2 Camera Settings
1 parent 88b78b6 commit 9c62fd3

File tree

9 files changed

+72
-54
lines changed

9 files changed

+72
-54
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ BabbleApp/babble_settings.backup
77
BabbleApp/build
88
BabbleApp/dist
99
/vivetest
10+
/training
11+
.vscode

BabbleApp/camera.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import time
88

99
from colorama import Fore
10-
from config import BabbleConfig
10+
from config import BabbleConfig, BabbleSettingsConfig
1111
from enum import Enum
1212

1313
WAIT_TIME = 0.1
@@ -37,9 +37,11 @@ def __init__(
3737
capture_event: "threading.Event",
3838
camera_status_outgoing: "queue.Queue[CameraState]",
3939
camera_output_outgoing: "queue.Queue",
40+
settings: BabbleSettingsConfig,
4041
):
4142
self.camera_status = CameraState.CONNECTING
4243
self.config = config
44+
self.settings = settings
4345
self.camera_index = camera_index
4446
self.camera_address = config.capture_source
4547
self.camera_status_outgoing = camera_status_outgoing
@@ -105,6 +107,9 @@ def run(self):
105107
return
106108
self.current_capture_source = self.config.capture_source
107109
self.cv2_camera = cv2.VideoCapture(self.current_capture_source)
110+
if not self.settings.gui_cam_resolution_x == 0: self.cv2_camera.set(cv2.CAP_PROP_FRAME_WIDTH, self.settings.gui_cam_resolution_x)
111+
if not self.settings.gui_cam_resolution_y == 0: self.cv2_camera.set(cv2.CAP_PROP_FRAME_HEIGHT, self.settings.gui_cam_resolution_y)
112+
if not self.settings.gui_cam_framerate == 0: self.cv2_camera.set(cv2.CAP_PROP_FPS, self.settings.gui_cam_framerate)
108113
should_push = False
109114
else:
110115
# We don't have a capture source to try yet, wait for one to show up in the GUI.

BabbleApp/camera_widget.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ def __init__(self, widget_id: Tab, main_config: BabbleConfig, osc_queue: Queue):
7575
self.capture_event,
7676
self.camera_status_queue,
7777
self.capture_queue,
78+
self.settings
7879
)
7980

8081
self.roi_layout = [

BabbleApp/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ class BabbleSettingsConfig(BaseModel):
3535
gui_model_file: str = 'Models/EFV2300K45E100P2.onnx'
3636
gui_use_gpu: bool = False
3737
calib_array: str = None
38+
gui_cam_resolution_x: int = 0
39+
gui_cam_resolution_y: int = 0
40+
gui_cam_framerate: int = 0
3841

3942
class BabbleConfig(BaseModel):
4043
version: int = 1

BabbleApp/general_settings_widget.py

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ def __init__(self, widget_id: Tab, main_config: BabbleSettingsConfig, osc_queue:
1616
self.gui_ROSC = f"-ROSC{widget_id}-"
1717
self.gui_update_check = f"-UPDATECHECK{widget_id}-"
1818
self.gui_osc_location = f"-OSCLOCATION{widget_id}-"
19+
self.gui_cam_resolution_x = f"-CAMRESX{widget_id}-"
20+
self.gui_cam_resolution_y = f"-CAMRESY{widget_id}-"
21+
self.gui_cam_framerate = f"-CAMFRAMERATE{widget_id}-"
1922
self.main_config = main_config
2023
self.config = main_config.settings
2124
self.osc_queue = osc_queue
@@ -93,7 +96,39 @@ def __init__(self, widget_id: Tab, main_config: BabbleSettingsConfig, osc_queue:
9396
size=(0,10),
9497
tooltip = "OSC address we use for recalibrating.",
9598
),
96-
]
99+
],
100+
[
101+
sg.Text("Camera Settings:", background_color='#242224'),
102+
],
103+
[
104+
sg.Text("X Resolution:", background_color='#424042'),
105+
sg.InputText(
106+
self.config.gui_cam_resolution_x,
107+
key=self.gui_cam_resolution_x,
108+
size=(0,20),
109+
tooltip = "X capture resolution. Default = 0",
110+
),
111+
112+
# ],
113+
# [
114+
sg.Text("Y Resolution:", background_color='#424042'),
115+
sg.InputText(
116+
self.config.gui_cam_resolution_y,
117+
key=self.gui_cam_resolution_y,
118+
size=(0,10),
119+
tooltip = "Y capture resolution. Default = 0",
120+
),
121+
122+
# ],
123+
# [
124+
sg.Text("Framerate:", background_color='#424042'),
125+
sg.InputText(
126+
self.config.gui_cam_framerate,
127+
key=self.gui_cam_framerate,
128+
size=(0,10),
129+
tooltip = "Capture framerate. Default = 0",
130+
),
131+
],
97132

98133
]
99134

@@ -179,6 +214,17 @@ def render(self, window, event, values):
179214
self.config.gui_osc_location = values[self.gui_osc_location]
180215
changed = True
181216

217+
if self.config.gui_cam_resolution_x != values[self.gui_cam_resolution_x]:
218+
self.config.gui_cam_resolution_x = values[self.gui_cam_resolution_x]
219+
changed = True
220+
221+
if self.config.gui_cam_resolution_y != values[self.gui_cam_resolution_y]:
222+
self.config.gui_cam_resolution_y = values[self.gui_cam_resolution_y]
223+
changed = True
224+
225+
if self.config.gui_cam_framerate != values[self.gui_cam_framerate]:
226+
self.config.gui_cam_framerate = values[self.gui_cam_framerate]
227+
changed = True
182228

183229
if changed:
184230
self.main_config.save()

babble_settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"version": 1, "cam": {"rotation_angle": 0, "roi_window_x": 0, "roi_window_y": 0, "roi_window_w": 0, "roi_window_h": 0, "capture_source": null, "use_calibration": false, "use_n_calibration": true, "gui_vertical_flip": false, "gui_horizontal_flip": false}, "settings": {"gui_min_cutoff": "15.5004", "gui_speed_coefficient": "0.62", "gui_osc_address": "127.0.0.1", "gui_osc_port": 8888, "gui_osc_receiver_port": 9001, "gui_osc_recalibrate_address": "/avatar/parameters/babble_recalibrate", "gui_update_check": true, "gui_ROSC": false, "gui_osc_location": "", "gui_multiply": 1, "gui_model_file": "Models/EFV2300K45E100P2.onnx", "gui_use_gpu": false, "calib_array": null, "gui_cam_resolution_x": 0, "gui_cam_resolution_y": 0, "gui_cam_framerate": 0}, "cam_display_id": 0}

cam_viewer.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import cv2
2+
3+
cap = cv2.VideoCapture(0)
4+
#cap.set(cv2.CAP_PROP_FRAME_WIDTH, 0)
5+
#cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 0)
6+
cap.set(cv2.CAP_PROP_FPS, 120)
7+
8+
while cap.isOpened():
9+
yeah, img = cap.read()
10+
cv2.imshow('win', img)
11+
if cv2.waitKey(1) & 0xFF == ord('q'):
12+
break
File renamed without changes.

one_euro_filter.py

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)