mirror of
https://github.com/Project-Babble/ProjectBabble.git
synced 2026-12-04 15:52:21 -08:00
Fix: Decouple OSC from GUI render loop
This commit is contained in:
1 parent
fc56aba7ef
commit
2d1239b3a4
2 files changed
+21
-22
No files matched your search
@@ -49,6 +49,7 @@ class BabbleProcessor:
|
||||
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
|
||||
@@ -61,6 +62,7 @@ class BabbleProcessor:
|
||||
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
|
||||
@@ -111,20 +113,22 @@ class BabbleProcessor:
|
||||
)
|
||||
|
||||
def output_images_and_update(self, output_information: CamInfo):
|
||||
try:
|
||||
image_stack = np.concatenate(
|
||||
(
|
||||
cv2.cvtColor(self.current_image_gray, cv2.COLOR_GRAY2BGR),
|
||||
),
|
||||
axis=1,
|
||||
)
|
||||
self.image_queue_outgoing.put((image_stack, output_information))
|
||||
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[ERROR] Size of frames to display are of unequal sizes.\033[0m')
|
||||
image_stack = np.concatenate(
|
||||
(
|
||||
cv2.cvtColor(self.current_image_gray, cv2.COLOR_GRAY2BGR),
|
||||
),
|
||||
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))
|
||||
|
||||
pass
|
||||
def capture_crop_rotate_image(self):
|
||||
# Get our current frame
|
||||
|
||||
@@ -194,7 +198,6 @@ class BabbleProcessor:
|
||||
print("\033[94m[INFO] Exiting Tracking thread\033[0m")
|
||||
return
|
||||
|
||||
|
||||
if self.config.roi_window_w <= 0 or self.config.roi_window_h <= 0:
|
||||
# At this point, we're waiting for the user to set up the ROI window in the GUI.
|
||||
# Sleep a bit while we wait.
|
||||
@@ -202,8 +205,6 @@ class BabbleProcessor:
|
||||
return
|
||||
continue
|
||||
|
||||
|
||||
|
||||
try:
|
||||
if self.capture_queue_incoming.empty():
|
||||
self.capture_event.set()
|
||||
@@ -212,7 +213,7 @@ class BabbleProcessor:
|
||||
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
|
||||
@@ -234,11 +235,11 @@ class BabbleProcessor:
|
||||
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):
|
||||
return self.FRAMESIZE
|
||||
return self.FRAMESIZE
|
||||
@@ -65,6 +65,7 @@ class CameraWidget:
|
||||
self.capture_queue,
|
||||
self.image_queue,
|
||||
self.cam_id,
|
||||
self.osc_queue,
|
||||
)
|
||||
|
||||
|
||||
@@ -413,8 +414,5 @@ class CameraWidget:
|
||||
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
|
||||
Reference in new issue
Block a user