From 015253fda0525a9c82e3debb322de2053fd369fd Mon Sep 17 00:00:00 2001 From: Rames The Generic <53163624+RamesTheGeneric@users.noreply.github.com> Date: Sat, 20 Jan 2024 15:55:31 -0500 Subject: [PATCH] Fixed Auto ROI not getting an image when no ROI set. Auto ROI can now run without an roi being set initially. Also fixed a bug with the osc receiver that prevented it from initializing. --- BabbleApp/camera_widget.py | 20 ++++++++++---------- BabbleApp/landmark_model_loader.py | 8 ++++---- BabbleApp/landmark_processor.py | 4 ++-- BabbleApp/osc.py | 7 +++++-- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/BabbleApp/camera_widget.py b/BabbleApp/camera_widget.py index 598df65..93f180e 100644 --- a/BabbleApp/camera_widget.py +++ b/BabbleApp/camera_widget.py @@ -44,6 +44,7 @@ class CameraWidget: self.settings_config = main_config.settings self.config = main_config.cam self.settings = main_config.settings + self.maybe_image = None if self.cam_id == Tab.CAM: self.config = main_config.cam else: @@ -255,7 +256,7 @@ class CameraWidget: changed = True - + if self.config.rotation_angle != values[self.gui_rotation_slider]: self.config.rotation_angle = int(values[self.gui_rotation_slider]) changed = True @@ -310,19 +311,17 @@ class CameraWidget: if event == self.gui_autoroi: print("Auto ROI") - #image = self.image_queue.get() - #image = self.babble_landmark.get_frame() # Get image for pfld - #print(image) - #print(len(image)) - #print(image) - #cv2.imwrite("yeah.png", image) - self.babble_landmark.infer_frame() - output = self.babble_landmark.output + #needs_roi_set = self.config.roi_window_h <= 0 or self.config.roi_window_w <= 0 + self.babble_landmark.infer_frame(image = self.maybe_image[0]) + output = self.babble_landmark.output[0] + rotation = self.babble_landmark.output[1] + print(f'Rotation: {rotation}') print(f"Output: {output}") self.x1 = output[2] self.y1 = output[3] self.x0 = output[0] self.y0 = output[1] + window[self.gui_rotation_slider].update(value = rotation) self.config.roi_window_x = min([self.x0, self.x1]) self.config.roi_window_y = min([self.y0, self.y1]) self.config.roi_window_w = abs(self.x0 - self.x1) @@ -370,6 +369,7 @@ class CameraWidget: if self.roi_queue.empty(): self.capture_event.set() maybe_image = self.roi_queue.get(block=False) + self.maybe_image = maybe_image imgbytes = cv2.imencode(".ppm", maybe_image[0])[1].tobytes() graph = window[self.gui_roi_selection] if self.figure: @@ -400,4 +400,4 @@ class CameraWidget: if cam_info.info_type != CamInfoOrigin.FAILURE: self.osc_queue.put((self.cam_id, cam_info)) except Empty: - pass + pass \ No newline at end of file diff --git a/BabbleApp/landmark_model_loader.py b/BabbleApp/landmark_model_loader.py index e391f37..1da5f19 100644 --- a/BabbleApp/landmark_model_loader.py +++ b/BabbleApp/landmark_model_loader.py @@ -28,8 +28,8 @@ def run_model(self): # Replace transforms n shit for the pfld model self.output = output -def write_image(self): # Debug function for development, remove once pfld is implemented. - frame = cv2.resize(self.current_image_gray, (256, 256)) - cv2.imwrite("yeah.png", frame) +def write_image(self, image): # Placeholder function for development, replace all instances with run_model() once pfld is implemented. + frame = cv2.resize(image, (256, 256)) + cv2.imwrite("yeah.png", frame) # Write the clean, untransformed frame to show that the frame is clean for pfld print("Image Wrote") - self.output = (0, 0, 100, 100) \ No newline at end of file + self.output = ((0, 0, 100, 100), 25) # Return ROI box and Rotation information. \ No newline at end of file diff --git a/BabbleApp/landmark_processor.py b/BabbleApp/landmark_processor.py index 14568a1..d642a47 100644 --- a/BabbleApp/landmark_processor.py +++ b/BabbleApp/landmark_processor.py @@ -115,8 +115,8 @@ class LandmarkProcessor: def get_frame(self): return self.current_image_gray_clean - def infer_frame(self): - return write_image(self) + def infer_frame(self, image): + return write_image(self, image) def output_images_and_update(self, output_information: CamInfo): try: diff --git a/BabbleApp/osc.py b/BabbleApp/osc.py index 6f3bf7d..30b7fcb 100644 --- a/BabbleApp/osc.py +++ b/BabbleApp/osc.py @@ -5,6 +5,7 @@ import threading from enum import IntEnum import time from config import BabbleConfig +import traceback class Tab(IntEnum): CAM = 0 @@ -90,6 +91,7 @@ class VRChatOSCReceiver: self.cancellation_event = cancellation_event self.dispatcher = dispatcher.Dispatcher() self.cams = cams # we cant import CameraWidget so any type it is + print("OSC_INIT") try: self.server = osc_server.OSCUDPServer((self.config.gui_osc_address, int(self.config.gui_osc_receiver_port)), self.dispatcher) except: @@ -106,17 +108,18 @@ class VRChatOSCReceiver: if type(osc_value) != bool: return # just incase we get anything other than bool if osc_value: for cam in self.cams: - cam.ransac.calibration_frame_counter = 300 + cam.babble_cnn.calibration_frame_counter = 300 PlaySound('Audio/start.wav', SND_FILENAME | SND_ASYNC) def run(self): # bind what function to run when specified OSC message is received try: - self.dispatcher.map(self.config.gui_osc_recalibrate_address, self.recalibrate_cams) + self.dispatcher.map(self.config.gui_osc_recalibrate_address, self.recalibrate_mouth) # start the server print("\033[92m[INFO] VRChatOSCReceiver serving on {}\033[0m".format(self.server.server_address)) self.server.serve_forever() except: + traceback.print_exc() print(f"\033[91m[ERROR] OSC Receive port: {self.config.gui_osc_receiver_port} occupied.\033[0m") \ No newline at end of file