Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Decouple OSC from GUI render loop #56

Merged
merged 3 commits into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions BabbleApp/babble_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def __init__(
capture_queue_incoming: "queue.Queue(maxsize=2)",
image_queue_outgoing: "queue.Queue(maxsize=2)",
cam_id,
osc_queue: queue.Queue,
):
self.main_config = BabbleSettingsConfig
self.config = config
Expand All @@ -63,6 +64,7 @@ def __init__(
self.cancellation_event = cancellation_event
self.capture_event = capture_event
self.cam_id = cam_id
self.osc_queue = osc_queue

# Image state
self.previous_image = None
Expand Down Expand Up @@ -126,15 +128,19 @@ def output_images_and_update(self, output_information: CamInfo):
axis=1,
)
self.image_queue_outgoing.put((image_stack, output_information))
if self.image_queue_outgoing.qsize() > 1:
self.image_queue_outgoing.get()

self.previous_image = self.current_image
self.previous_rotation = self.config.rotation_angle

# Relay information to OSC
self.osc_queue.put((None, output_information))
except: # If this fails it likely means that the images are not the same size for some reason.
print(
f'\033[91m[{lang._instance.get_string("log.error")}] {lang._instance.get_string("error.size")}.\033[0m'
)

pass

def capture_crop_rotate_image(self):
# Get our current frame

Expand Down Expand Up @@ -221,7 +227,7 @@ def run(self):
self.current_image,
self.current_frame_number,
self.current_fps,
) = self.capture_queue_incoming.get(block=True, timeout=0.2)
) = self.capture_queue_incoming.get(block=True, timeout=0.1)
except queue.Empty:
# print("No image available")
continue
Expand All @@ -246,10 +252,10 @@ def run(self):
run_model(self)
if self.settings.use_calibration:
self.output = cal.cal_osc(self, self.output)

# else:
# pass
# print(self.output)

self.output_images_and_update(CamInfo(self.current_algo, self.output))

def get_framesize(self):
Expand Down
2 changes: 1 addition & 1 deletion BabbleApp/babbleapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def main():
# Check to see if we have an ROI. If not, bring up ROI finder GUI.

# Spawn worker threads
osc_queue: queue.Queue[tuple[bool, int, int]] = queue.Queue(maxsize=2)
osc_queue: queue.Queue[tuple[bool, int, int]] = queue.Queue(maxsize=10)
osc = VRChatOSC(cancellation_event, osc_queue, config)
osc_thread = threading.Thread(target=osc.run)
# start worker threads
Expand Down
4 changes: 1 addition & 3 deletions BabbleApp/camera_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def __init__(self, widget_id: Tab, main_config: BabbleConfig, osc_queue: Queue):
self.capture_queue,
self.image_queue,
self.cam_id,
self.osc_queue,
)

self.camera_status_queue = Queue(maxsize=2)
Expand Down Expand Up @@ -516,8 +517,5 @@ def render(self, window, event, values):
imgbytes = cv2.imencode(".ppm", maybe_image)[1].tobytes()
window[self.gui_tracking_image].update(data=imgbytes)

# Relay information to OSC
if cam_info.info_type != CamInfoOrigin.FAILURE:
self.osc_queue.put((self.cam_id, cam_info))
except Empty:
pass
6 changes: 4 additions & 2 deletions BabbleApp/landmark_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def __init__(

def get_frame(self):
return self.current_image_gray_clean

def infer_frame(self, image):
return write_image(self, image)

Expand All @@ -127,12 +127,14 @@ def output_images_and_update(self, output_information: CamInfo):
axis=1,
)
self.image_queue_outgoing.put((image_stack, output_information))
if self.image_queue_outgoing.qsize() > 1:
self.image_queue_outgoing.get()

self.previous_image = self.current_image
self.previous_rotation = self.config.rotation_angle
except: # If this fails it likely means that the images are not the same size for some reason.
print('\033[91m[{lang._instance.get_string("log.error")}] Size of frames to display are of unequal sizes.\033[0m')

pass
def capture_crop_rotate_image(self):
# Get our current frame

Expand Down
Loading