Skip to content

Commit b999e3d

Browse files
Merge pull request #56 from SnuffSocket/osc-branch
Fix: Decouple OSC from GUI render loop
2 parents 1cba6d3 + 179d899 commit b999e3d

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

BabbleApp/babble_processor.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def __init__(
5151
capture_queue_incoming: "queue.Queue(maxsize=2)",
5252
image_queue_outgoing: "queue.Queue(maxsize=2)",
5353
cam_id,
54+
osc_queue: queue.Queue,
5455
):
5556
self.main_config = BabbleSettingsConfig
5657
self.config = config
@@ -63,6 +64,7 @@ def __init__(
6364
self.cancellation_event = cancellation_event
6465
self.capture_event = capture_event
6566
self.cam_id = cam_id
67+
self.osc_queue = osc_queue
6668

6769
# Image state
6870
self.previous_image = None
@@ -130,15 +132,19 @@ def output_images_and_update(self, output_information: CamInfo):
130132
axis=1,
131133
)
132134
self.image_queue_outgoing.put((image_stack, output_information))
135+
if self.image_queue_outgoing.qsize() > 1:
136+
self.image_queue_outgoing.get()
137+
133138
self.previous_image = self.current_image
134139
self.previous_rotation = self.config.rotation_angle
140+
141+
# Relay information to OSC
142+
self.osc_queue.put((None, output_information))
135143
except: # If this fails it likely means that the images are not the same size for some reason.
136144
print(
137145
f'\033[91m[{lang._instance.get_string("log.error")}] {lang._instance.get_string("error.size")}.\033[0m'
138146
)
139147

140-
pass
141-
142148
def capture_crop_rotate_image(self):
143149
# Get our current frame
144150

@@ -225,7 +231,7 @@ def run(self):
225231
self.current_image,
226232
self.current_frame_number,
227233
self.current_fps,
228-
) = self.capture_queue_incoming.get(block=True, timeout=0.2)
234+
) = self.capture_queue_incoming.get(block=True, timeout=0.1)
229235
except queue.Empty:
230236
# print("No image available")
231237
continue
@@ -250,10 +256,10 @@ def run(self):
250256
run_model(self)
251257
if self.settings.use_calibration:
252258
self.output = cal.cal_osc(self, self.output)
253-
254259
# else:
255260
# pass
256261
# print(self.output)
262+
257263
self.output_images_and_update(CamInfo(self.current_algo, self.output))
258264

259265
def get_framesize(self):

BabbleApp/babbleapp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def main():
129129
# Check to see if we have an ROI. If not, bring up ROI finder GUI.
130130

131131
# Spawn worker threads
132-
osc_queue: queue.Queue[tuple[bool, int, int]] = queue.Queue(maxsize=2)
132+
osc_queue: queue.Queue[tuple[bool, int, int]] = queue.Queue(maxsize=10)
133133
osc = VRChatOSC(cancellation_event, osc_queue, config)
134134
osc_thread = threading.Thread(target=osc.run)
135135
# start worker threads

BabbleApp/camera_widget.py

Lines changed: 1 addition & 3 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_queue,
7676
self.image_queue,
7777
self.cam_id,
78+
self.osc_queue,
7879
)
7980

8081
self.camera_status_queue = Queue(maxsize=2)
@@ -518,8 +519,5 @@ def render(self, window, event, values):
518519
imgbytes = cv2.imencode(".ppm", maybe_image)[1].tobytes()
519520
window[self.gui_tracking_image].update(data=imgbytes)
520521

521-
# Relay information to OSC
522-
if cam_info.info_type != CamInfoOrigin.FAILURE:
523-
self.osc_queue.put((self.cam_id, cam_info))
524522
except Empty:
525523
pass

BabbleApp/landmark_processor.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def __init__(
117117

118118
def get_frame(self):
119119
return self.current_image_gray_clean
120-
120+
121121
def infer_frame(self, image):
122122
return write_image(self, image)
123123

@@ -130,12 +130,14 @@ def output_images_and_update(self, output_information: CamInfo):
130130
axis=1,
131131
)
132132
self.image_queue_outgoing.put((image_stack, output_information))
133+
if self.image_queue_outgoing.qsize() > 1:
134+
self.image_queue_outgoing.get()
135+
133136
self.previous_image = self.current_image
134137
self.previous_rotation = self.config.rotation_angle
135138
except: # If this fails it likely means that the images are not the same size for some reason.
136139
print('\033[91m[{lang._instance.get_string("log.error")}] Size of frames to display are of unequal sizes.\033[0m')
137140

138-
pass
139141
def capture_crop_rotate_image(self):
140142
# Get our current frame
141143

0 commit comments

Comments
 (0)