From 0e99fd3f21470144afdad7e05055fca1a06b860c Mon Sep 17 00:00:00 2001 From: Prohurtz <48768484+RedHawk989@users.noreply.github.com> Date: Sat, 13 Aug 2022 13:45:51 -0700 Subject: [PATCH] bug fix --- EyeTrackApp-SingleCam/eyetrackapp.spec | 2 +- EyeTrackApp-SingleCam/osc.py | 8 ++-- EyeTrackApp/camera_widget.py | 20 ++++---- EyeTrackApp/config.py | 4 +- EyeTrackApp/eye_processor.py | 42 ++++++++--------- EyeTrackApp/eyetrackapp.spec | 2 +- EyeTrackApp/osc.py | 64 ++++++++++++++++---------- 7 files changed, 78 insertions(+), 64 deletions(-) diff --git a/EyeTrackApp-SingleCam/eyetrackapp.spec b/EyeTrackApp-SingleCam/eyetrackapp.spec index c29dfed..896d2b7 100644 --- a/EyeTrackApp-SingleCam/eyetrackapp.spec +++ b/EyeTrackApp-SingleCam/eyetrackapp.spec @@ -1,4 +1,4 @@ -# -*- mode: python ; coding: utf-8 -*- +# -*- mode: py -3.6 ; coding: utf-8 -*- block_cipher = None diff --git a/EyeTrackApp-SingleCam/osc.py b/EyeTrackApp-SingleCam/osc.py index 3a9698d..e7cc0ef 100644 --- a/EyeTrackApp-SingleCam/osc.py +++ b/EyeTrackApp-SingleCam/osc.py @@ -33,10 +33,10 @@ class VRChatOSC: self.client.send_message("/avatar/parameters/LeftEye", eye_info.x) self.client.send_message("/avatar/parameters/EyesY", eye_info.y) if was_blinking: - self.client.send_message("/avatar/parameters/LeftEyeLid", float(1)) - self.client.send_message("/avatar/parameters/RightEyeLid", float(1)) + self.client.send_message("/avatar/parameters/LeftEyeLid", float(0)) + self.client.send_message("/avatar/parameters/RightEyeLid", float(0)) was_blinking = False else: - self.client.send_message("/avatar/parameters/LeftEyeLid", float(0)) - self.client.send_message("/avatar/parameters/RightEyeLid", float(0)) + self.client.send_message("/avatar/parameters/LeftEyeLid", float(1)) + self.client.send_message("/avatar/parameters/RightEyeLid", float(1)) was_blinking = True diff --git a/EyeTrackApp/camera_widget.py b/EyeTrackApp/camera_widget.py index 96efd1e..03c2440 100644 --- a/EyeTrackApp/camera_widget.py +++ b/EyeTrackApp/camera_widget.py @@ -26,7 +26,7 @@ class CameraWidget: self.gui_restart_calibration = f"-RESTARTCALIBRATION{widget_id}-" self.gui_recenter_eye = f"-RECENTEREYE{widget_id}-" self.gui_mode_readout = f"-APPMODE{widget_id}-" - self.gui_show_color_image = f"-SHOWCOLORIMAGE{widget_id}-" + # self.gui_show_color_image = f"-SHOWCOLORIMAGE{widget_id}-" self.gui_roi_message = f"-ROIMESSAGE{widget_id}-" self.osc_queue = osc_queue @@ -57,7 +57,7 @@ class CameraWidget: [ sg.Text("Threshold"), sg.Slider( - range=(0, 100), + range=(0, 110), default_value=self.config.threshold, orientation="h", key=self.gui_threshold_slider, @@ -84,11 +84,11 @@ class CameraWidget: [ sg.Button("Restart Calibration", key=self.gui_restart_calibration), sg.Button("Recenter Eye", key=self.gui_recenter_eye), - sg.Checkbox( - "Show Color Image:", - default=self.config.show_color_image, - key=self.gui_show_color_image, - ), + #sg.Checkbox( + # "Show Color Image:", + # default=self.config.show_color_image, + # key=self.gui_show_color_image, + #), ], [sg.Text("Mode:"), sg.Text("Calibrating", key=self.gui_mode_readout)], [sg.Image(filename="", key=self.gui_tracking_image)], @@ -210,9 +210,9 @@ class CameraWidget: self.config.vrc_eye_position_scalar = int(values[self.gui_scalar_slider]) changed = True - if self.config.show_color_image != values[self.gui_show_color_image]: - self.config.show_color_image = values[self.gui_show_color_image] - changed = True + # if self.config.show_color_image != values[self.gui_show_color_image]: + # self.config.show_color_image = values[self.gui_show_color_image] + # changed = True if changed: self.main_config.save() diff --git a/EyeTrackApp/config.py b/EyeTrackApp/config.py index d143e95..a34eebc 100644 --- a/EyeTrackApp/config.py +++ b/EyeTrackApp/config.py @@ -12,7 +12,7 @@ import json @dataclass class EyeTrackCameraConfig: threshold: "int" = 0 - rotation_angle: "int" = 0 + rotation_angle: "int" = 50 roi_window_x: "int" = 0 roi_window_y: "int" = 0 roi_window_w: "int" = 0 @@ -20,7 +20,7 @@ class EyeTrackCameraConfig: focal_length: "int" = 30 capture_source: "Union[int, str, None]" = None vrc_eye_position_scalar: "int" = 3000 - show_color_image: "bool" = False + #show_color_image: "bool" = False CONFIG_FILE_NAME = "eyetrack_settings.json" diff --git a/EyeTrackApp/eye_processor.py b/EyeTrackApp/eye_processor.py index 78fd333..4dabb6e 100644 --- a/EyeTrackApp/eye_processor.py +++ b/EyeTrackApp/eye_processor.py @@ -198,23 +198,23 @@ class EyeProcessor: def output_images_and_update( self, threshold_image, output_information: EyeInformation ): - if self.config.show_color_image: - image_stack = np.concatenate( - ( - self.current_image, - cv2.cvtColor(self.current_image_gray, cv2.COLOR_GRAY2BGR), - cv2.cvtColor(threshold_image, cv2.COLOR_GRAY2BGR), - ), - axis=1, - ) - else: - image_stack = np.concatenate( - ( - cv2.cvtColor(self.current_image_gray, cv2.COLOR_GRAY2BGR), - cv2.cvtColor(threshold_image, cv2.COLOR_GRAY2BGR), - ), - axis=1, - ) + # if self.config.show_color_image: + # image_stack = np.concatenate( + # ( + # self.current_image, + # cv2.cvtColor(self.current_image_gray, cv2.COLOR_GRAY2BGR), + # cv2.cvtColor(threshold_image, cv2.COLOR_GRAY2BGR), + # ), + # axis=1, + # ) + # else: + image_stack = np.concatenate( + ( + cv2.cvtColor(self.current_image_gray, cv2.COLOR_GRAY2BGR), + cv2.cvtColor(threshold_image, 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 @@ -258,7 +258,7 @@ class EyeProcessor: # something to do blob tracking on. _, larger_threshold = cv2.threshold( self.current_image_gray, - int(self.config.threshold + 25), + int(self.config.threshold + 15), 255, cv2.THRESH_BINARY, ) @@ -273,7 +273,7 @@ class EyeProcessor: return - + # define circle try: ht, wd = self.current_image_gray.shape[:2] @@ -310,7 +310,7 @@ class EyeProcessor: raise RuntimeError("No contours found for image") except: self.output_images_and_update( - larger_threshold, EyeInformation(InformationOrigin.FAILURE, 0, 0, False) + larger_threshold, EyeInformation(InformationOrigin.FAILURE, 0, 0, 0, False) ) return @@ -392,7 +392,7 @@ class EyeProcessor: self.output_images_and_update( larger_threshold, - EyeInformation(InformationOrigin.BLOB, out_x, out_y, w, False), + EyeInformation(InformationOrigin.BLOB, out_x, out_y, 0, False), ) return self.output_images_and_update( diff --git a/EyeTrackApp/eyetrackapp.spec b/EyeTrackApp/eyetrackapp.spec index 496eab3..b4d780f 100644 --- a/EyeTrackApp/eyetrackapp.spec +++ b/EyeTrackApp/eyetrackapp.spec @@ -1,4 +1,4 @@ -# -*- mode: python ; coding: utf-8 -*- +# -*- mode: py -3.6 ; coding: utf-8 -*- block_cipher = None diff --git a/EyeTrackApp/osc.py b/EyeTrackApp/osc.py index 828b899..2f8facb 100644 --- a/EyeTrackApp/osc.py +++ b/EyeTrackApp/osc.py @@ -25,11 +25,11 @@ class VRChatOSC: self.client = udp_client.SimpleUDPClient(VRChatOSC.OSC_IP, VRChatOSC.OSC_PORT) self.cancellation_event = cancellation_event self.msg_queue = msg_queue + yl = 0 + yr = 0 def run(self): - # Set blinking status to true when we start, just so we make sure we get to an eyelid open state - # no matter what. - was_blinking = True + while True: if self.cancellation_event.is_set(): print("Exiting OSC Queue") @@ -39,41 +39,55 @@ class VRChatOSC: except queue.Empty: continue # If we're not blinking, set position + print(eye_info.blink) if not eye_info.blink: if eye_id in [EyeId.RIGHT, EyeId.BOTH]: self.client.send_message( - "/avatar/parameters/RightEye", eye_info.x - ) - self.client.send_message( - "/avatar/parameters/EyesDilation", eye_info.pupil_dialation + "/avatar/parameters/RightEyeX", eye_info.x ) + # self.client.send_message( + # "/avatar/parameters/EyesDilation", eye_info.pupil_dialation + #) if eye_id in [EyeId.LEFT, EyeId.BOTH]: self.client.send_message( - "/avatar/parameters/LeftEye", eye_info.x - ) - self.client.send_message( - "/avatar/parameters/EyesDilation", eye_info.pupil_dialation + "/avatar/parameters/LeftEyeX", eye_info.x ) + - - self.client.send_message("/avatar/parameters/EyesY", eye_info.y) - if was_blinking: - if eye_id in [EyeId.LEFT, EyeId.BOTH]: - self.client.send_message( - "/avatar/parameters/LeftEyeLid", float(1) - ) - if eye_id in [EyeId.RIGHT, EyeId.BOTH]: - self.client.send_message( - "/avatar/parameters/RightEyeLid", float(1) - ) - was_blinking = False - else: if eye_id in [EyeId.LEFT, EyeId.BOTH]: + yl = eye_info.y + print('left y', yl) + + if eye_id in [EyeId.RIGHT, EyeId.BOTH]: + yr = eye_info.y + print('right y', yr) + + try: + y = abs((yl + yr) / 2) + self.client.send_message("/avatar/parameters/EyesY", y) + except: + print('Y ERROR') + + if eye_id in [EyeId.LEFT, EyeId.BOTH]: + self.client.send_message( "/avatar/parameters/LeftEyeLid", float(0) ) if eye_id in [EyeId.RIGHT, EyeId.BOTH]: + self.client.send_message( "/avatar/parameters/RightEyeLid", float(0) ) - was_blinking = True + + else: + if eye_id in [EyeId.LEFT, EyeId.BOTH]: + + self.client.send_message( + "/avatar/parameters/LeftEyeLid", float(1) + ) + if eye_id in [EyeId.RIGHT, EyeId.BOTH]: + + self.client.send_message( + "/avatar/parameters/RightEyeLid", float(1) + ) +