From 9331a5dca423cf6bd6b02d822ebc9f00691a2846 Mon Sep 17 00:00:00 2001 From: Blabzillaweasel Date: Sat, 8 Feb 2025 21:40:40 +1300 Subject: [PATCH] Add minimum inwards threshold --- EyeTrackApp/config.py | 5 +++-- .../modules/SmartInversionSettingsModule.py | 15 +++++++++++++++ EyeTrackApp/utils/smart_inversion.py | 2 +- conftest.py | 3 ++- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/EyeTrackApp/config.py b/EyeTrackApp/config.py index 448444e..5a0b108 100644 --- a/EyeTrackApp/config.py +++ b/EyeTrackApp/config.py @@ -220,9 +220,10 @@ class EyeTrackSettingsConfig(BaseModel): #SmartInversionTracking gui_smartinversion_enabled: bool = False gui_smartinversion_select_right: bool = True - gui_smartinversion_thresh: float = 0.25 - gui_smartinversion_frame_count: int = 10 + gui_smartinversion_thresh: float = 0.4 + gui_smartinversion_frame_count: int = 30 gui_smartinversion_smoothing_rate: float = 0.025 + gui_smartinversion_minthresh: float = 0.3 class EyeTrackConfig(BaseModel): version: int = 1 diff --git a/EyeTrackApp/settings/modules/SmartInversionSettingsModule.py b/EyeTrackApp/settings/modules/SmartInversionSettingsModule.py index cc980e9..464c21c 100644 --- a/EyeTrackApp/settings/modules/SmartInversionSettingsModule.py +++ b/EyeTrackApp/settings/modules/SmartInversionSettingsModule.py @@ -14,6 +14,7 @@ class SmartInversionValidationModule(BaseValidationModel): gui_smartinversion_thresh: Annotated[float, AfterValidator(try_convert_to_float)] gui_smartinversion_frame_count: Annotated[int, AfterValidator(try_convert_to_int)] gui_smartinversion_smoothing_rate: Annotated[float, AfterValidator(try_convert_to_float)] + gui_smartinversion_minthresh: Annotated[float, AfterValidator(try_convert_to_float)] class SmartInversionSettingsModule(BaseSettingsModule): def __init__(self, config, widget_id, **kwargs): @@ -24,6 +25,8 @@ class SmartInversionSettingsModule(BaseSettingsModule): self.gui_smartinversion_thresh = f"-gui_smartinversion_thresh{widget_id}-" self.gui_smartinversion_frame_count =f"-gui_smartinversion_frame_count{widget_id}" self.gui_smartinversion_smoothing_rate =f"-gui_smartinversion_smoothing_rate{widget_id}" + self.gui_smartinversion_minthresh =f"-gui_smartinversion_minthresh{widget_id}" + def get_layout(self): @@ -68,6 +71,18 @@ class SmartInversionSettingsModule(BaseSettingsModule): ) ), ], + [ + sg.Text("Inwards Look Threshold", background_color=BACKGROUND_COLOR), + sg.InputText( + self.config.gui_smartinversion_minthresh, + key=self.gui_smartinversion_minthresh, + size=(0, 10), + tooltip=( + "Sets the minimum distance of looking in that's required before state can chaned to cross-eyed." + "\n Lower value will make cross-eye detection more sensitive." + ) + ), + ], [ sg.Text("Inversion Trigger Frame Count", background_color=BACKGROUND_COLOR), sg.InputText( diff --git a/EyeTrackApp/utils/smart_inversion.py b/EyeTrackApp/utils/smart_inversion.py index 76cf237..628d39b 100644 --- a/EyeTrackApp/utils/smart_inversion.py +++ b/EyeTrackApp/utils/smart_inversion.py @@ -38,7 +38,7 @@ def smart_inversion(self, var, out_x, out_y): #Checks if the eyes are no longer inverted, and then clears inversion if the conditions haven't been true for a specified number of frames. elif self.smartinversion_is_inverted and ( - not (var.l_eye_x > 0 and var.r_eye_x < 0) or + not (var.l_eye_x > self.settings.gui_smartinversion_minthresh and var.r_eye_x < -self.settings.gui_smartinversion_minthresh) or abs(var.l_eye_x - var.r_eye_x) <= self.settings.gui_smartinversion_thresh ): diff --git a/conftest.py b/conftest.py index f6d8a01..46210fa 100644 --- a/conftest.py +++ b/conftest.py @@ -78,9 +78,10 @@ def eyetrack_settings_config(): #Smart Inversion Tracking gui_smartinversion_enabled=False, gui_smartinversion_select_right=True, - gui_smartinversion_thresh=0.5, + gui_smartinversion_thresh=0.4, gui_smartinversion_frame_count=10, gui_smartinversion_smoothing_rate=0.025, + gui_smartinversion_minthresh=0.3, )