Skip to content

Commit bf2d1fc

Browse files
committed
fix osc location prefix, cleanup
1 parent 4fb7050 commit bf2d1fc

File tree

7 files changed

+13
-256
lines changed

7 files changed

+13
-256
lines changed

BabbleApp/calib.json

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

BabbleApp/config.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class BabbleCameraConfig(BaseModel):
1919
use_calibration: bool = False
2020
gui_vertical_flip: bool = False
2121
gui_horizontal_flip: bool = False
22+
2223
class BabbleSettingsConfig(BaseModel):
2324
gui_min_cutoff: str = "15.5004"
2425
gui_speed_coefficient: str = "0.62"
@@ -33,9 +34,6 @@ class BabbleSettingsConfig(BaseModel):
3334
gui_model_file: str = 'Models/EFV2300K45E100P2.onnx'
3435
gui_use_gpu: bool = False
3536
calib_array: str = None
36-
# gui_vertical_flip: bool = False
37-
# gui_horizontal_flip: bool = False
38-
3937

4038
class BabbleConfig(BaseModel):
4139
version: int = 1

BabbleApp/general_settings_widget.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import PySimpleGUI as sg
2-
32
from config import BabbleSettingsConfig
43
from osc import Tab
54
from queue import Queue
@@ -196,6 +195,11 @@ def render(self, window, event, values):
196195
self.config.gui_ROSC = values[self.gui_ROSC]
197196
changed = True
198197

198+
if self.config.gui_osc_location != values[self.gui_osc_location]:
199+
self.config.gui_osc_location = values[self.gui_osc_location]
200+
changed = True
201+
202+
199203
if changed:
200204
self.main_config.save()
201205
self.osc_queue.put((Tab.SETTINGS))

BabbleApp/osc.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
2-
from pythonosc import udp_client
3-
from pythonosc import osc_server
4-
from pythonosc import dispatcher
5-
from utils.misc_utils import PlaySound,SND_FILENAME,SND_ASYNC
1+
from pythonosc import udp_client, osc_server, dispatcher
2+
from utils.misc_utils import PlaySound, SND_FILENAME, SND_ASYNC
63
import queue
74
import threading
85
from enum import IntEnum
@@ -17,6 +14,7 @@ class Tab(IntEnum):
1714

1815
def output_osc(array, self):
1916
location = self.config.gui_osc_location
17+
print(self.config.gui_osc_location)
2018
multi = self.config.gui_multiply
2119
self.client.send_message(location + "/cheekPuffLeft", array[0] * multi)
2220
self.client.send_message(location + "/cheekPuffRight", array[1] * multi)
@@ -75,8 +73,6 @@ def __init__(self, cancellation_event: threading.Event, msg_queue: queue.Queue[t
7573
self.cam = Tab.CAM
7674

7775
def run(self):
78-
start = time.time()
79-
last_blink = time.time()
8076
while True:
8177
if self.cancellation_event.is_set():
8278
print("\033[94m[INFO] Exiting OSC Queue\033[0m")

BabbleApp/osc_calibrate_filter.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
import numpy as np
2-
32
from enum import IntEnum
43
from utils.misc_utils import PlaySound, SND_FILENAME, SND_ASYNC
54

65
class CamId(IntEnum):
7-
RIGHT = 0
8-
LEFT = 1
9-
BOTH = 2
10-
SETTINGS = 3
11-
6+
CAM = 0
7+
SETTINGS = 1
128

139
class cal():
1410
def cal_osc(self, array):
@@ -43,19 +39,12 @@ def cal_osc(self, array):
4339
print("[INFO] Calibration completed.")
4440

4541
PlaySound('Audio/completed.wav', SND_FILENAME | SND_ASYNC)
46-
if self.calibration_frame_counter == 10:
4742

48-
self.calibration_frame_counter -= 1
4943
elif self.calibration_frame_counter != None:
5044

5145
self.val_list.append(array)
52-
53-
54-
# self.calibrate_config = np.vstack((self.calibrate_config, array.T))
55-
# np.append(self.calibrate_config, array.reshape(-1, 1), axis=1)
56-
5746
self.calibration_frame_counter -= 1
58-
# print(self.settings.calib_array)
47+
5948
if self.settings.calib_array is not None and self.config.use_calibration:
6049
self.min_max_array = np.fromstring(self.settings.calib_array.replace('[', '').replace(']', ''), sep=',')
6150
self.min_max_array = self.min_max_array.reshape((2, 45))
@@ -73,5 +62,4 @@ def cal_osc(self, array):
7362
calibrated_array[i] = calibrated_value
7463
array = calibrated_array
7564

76-
7765
return array

BabbleApp/utils/__init__.py

Whitespace-only changes.

BabbleApp/utils/misc_utils.py

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -10,51 +10,4 @@ def PlaySound(*args, **kwargs): pass
1010
import winsound
1111
PlaySound = winsound.PlaySound
1212
SND_FILENAME = winsound.SND_FILENAME
13-
SND_ASYNC = winsound.SND_ASYNC
14-
15-
def clamp(x, low, high):
16-
return max(low, min(x, high))
17-
18-
19-
def lst_median(lst, ordered=False):
20-
# https://github.com/emilianavt/OpenSeeFace/blob/6f24efc4f58eb7cca47ec2146d934eabcc207e46/remedian.py
21-
assert lst, "median needs a non-empty list"
22-
n = len(lst)
23-
p = q = n // 2
24-
if n < 3:
25-
p, q = 0, n - 1
26-
else:
27-
lst = lst if ordered else sorted(lst)
28-
if not n % 2: # for even-length lists, use mean of mid 2 nums
29-
q = p - 1
30-
return lst[p] if p == q else (lst[p] + lst[q]) / 2
31-
32-
33-
class FastMedian:
34-
# https://github.com/emilianavt/OpenSeeFace/blob/6f24efc4f58eb7cca47ec2146d934eabcc207e46/remedian.py
35-
# Initialization
36-
def __init__(self, inits: typing.Optional[typing.Sequence] = [], k=64): # after some experimentation, 64 works ok
37-
self.all, self.k = [], k
38-
self.more, self.__median = None, None
39-
if inits is not None:
40-
[self + x for x in inits]
41-
42-
# When full, push the median of current values to next list, then reset.
43-
def __add__(self, x):
44-
self.__median = None
45-
self.all.append(x) # It would be faster to pre-allocate an array and assign it by index.
46-
if len(self.all) == self.k:
47-
self.more = self.more or FastMedian(k=self.k)
48-
self.more + self.__medianPrim(self.all)
49-
# It's going to be slower because of the re-allocation.
50-
self.all = [] # reset
51-
52-
# If there is a next list, ask its median. Else, work it out locally.
53-
def median(self):
54-
return self.more.median() if self.more else self.__medianPrim(self.all)
55-
56-
# Only recompute median if we do not know it already.
57-
def __medianPrim(self, all):
58-
if self.__median is None:
59-
self.__median = lst_median(all, ordered=False)
60-
return self.__median
13+
SND_ASYNC = winsound.SND_ASYNC

0 commit comments

Comments
 (0)