Addition of center gaze logic and removal of abs(left - right) check

This commit is contained in:
Blabzillaweasel 2025-02-09 19:10:51 +13:00
parent 8939c020ff
commit db1fa320bb
4 changed files with 25 additions and 37 deletions

View File

@ -225,7 +225,6 @@ class EyeTrackSettingsConfig(BaseModel):
#SmartInversionTracking
gui_smartinversion_enabled: bool = False
gui_smartinversion_select_right: bool = True
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

View File

@ -11,7 +11,6 @@ from settings.modules.CommonFieldValidators import try_convert_to_int
class SmartInversionValidationModule(BaseValidationModel):
gui_smartinversion_enabled: bool
gui_smartinversion_select_right: bool
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)]
@ -23,7 +22,6 @@ class SmartInversionSettingsModule(BaseSettingsModule):
self.validation_model = SmartInversionValidationModule
self.gui_smartinversion_enabled = f"-gui_smartinversion_enabled{widget_id}-"
self.gui_smartinversion_select_right = f"-gui_smartinversion_select_right{widget_id}-"
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}"
@ -61,18 +59,6 @@ class SmartInversionSettingsModule(BaseSettingsModule):
tooltip="Uses the right eye as the tracked eye.",
)
],
[
sg.Text("Max. X-Axis Difference", background_color=BACKGROUND_COLOR),
sg.InputText(
self.config.gui_smartinversion_thresh,
key=self.gui_smartinversion_thresh,
size=(0, 10),
tooltip=(
"Sets the maximum allowed difference in eye position (x-axis) to determine if the eyes are cross-eyed or not."
"\n Lower value will make cross-eye detection more sensitive."
)
),
],
[
sg.Text("Inwards Look Threshold", background_color=BACKGROUND_COLOR),
sg.InputText(

View File

@ -14,8 +14,8 @@ def smart_inversion(self, var, out_x, out_y):
self.smartinversion_smoothing_progress = 0
if not hasattr(self, "smartinversion_smoothed_eye_x"):
self.smartinversion_smoothed_eye_x = 0.0
if not hasattr(self, "smartinversion_previous_inversion_state"):
self.smartinversion_previous_inversion_state = False
if not hasattr(self, "smartinversion_stare_ahead"):
self.smartinversion_stare_ahead = False
#Updates eye positions with latest
if self.eye_id == EyeId.LEFT:
@ -39,52 +39,56 @@ def smart_inversion(self, var, out_x, out_y):
recessive_eye = EyeId.RIGHT
dominant_eye = EyeId.LEFT
#Checks if eyes are straight, and then sets eye gaze forward until inversion threshold is met
if (0 < var.l_eye_x <= self.settings.gui_smartinversion_minthresh) and (self.settings.gui_smartinversion_minthresh <= var.r_eye_x < 0):
tracked_eye_x = 0
if not self.smartinversion_stare_ahead:
self.smartinversion_smoothing_progress = 1
self.smartinversion_is_inverted = False
self.smartinversion_stare_ahead = True
#Checks if eyes are inverted, and then activates inversion if the conditions have been true for a specified number of frames.
if (var.l_eye_x > self.settings.gui_smartinversion_minthresh and var.r_eye_x < -self.settings.gui_smartinversion_minthresh) and (abs(var.l_eye_x - var.r_eye_x) > self.settings.gui_smartinversion_thresh):
if (var.l_eye_x > self.settings.gui_smartinversion_minthresh and var.r_eye_x < -self.settings.gui_smartinversion_minthresh):
self.smartinversion_inverted_frame_count = min(self.smartinversion_inverted_frame_count + 1, self.settings.gui_smartinversion_frame_count)
if self.smartinversion_inverted_frame_count == self.settings.gui_smartinversion_frame_count:
if not self.smartinversion_is_inverted:
self.smartinversion_is_inverted = True
self.smartinversion_smoothing_progress = 1
self.smartinversion_normal_frame_count = 0
self.smartinversion_stare_ahead = False
tracked_eye_x = 0
print(f"Inversion Activated")
#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 > 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
):
elif self.smartinversion_is_inverted and (not (var.l_eye_x > self.settings.gui_smartinversion_minthresh and var.r_eye_x < -self.settings.gui_smartinversion_minthresh)):
self.smartinversion_normal_frame_count = min(self.smartinversion_normal_frame_count + 1, self.settings.gui_smartinversion_frame_count)
if self.smartinversion_normal_frame_count == self.settings.gui_smartinversion_frame_count:
if self.smartinversion_is_inverted:
self.smartinversion_is_inverted = False
self.smartinversion_inverted_frame_count = 0
self.smartinversion_stare_ahead = False
print(f"Inversion Cleared")
out_x = tracked_eye_x
out_y = tracked_eye_y
#Checks if the inversion state has recently been toggled, and activates smoothing
if self.smartinversion_previous_inversion_state != self.smartinversion_is_inverted:
self.smartinversion_smoothing_progress = 1
self.smartinversion_previous_inversion_state = self.smartinversion_is_inverted
"""#Logic if smoothing is activated
#Logic if smoothing is activated
if self.smartinversion_smoothing_progress > 0:
smartinversion_lerp_factor = (1 - self.smartinversion_smoothing_progress)
if not self.smartinversion_is_inverted and self.eye_id == recessive_eye:
self.smartinversion_smoothed_eye_x += (tracked_eye_x - self.smartinversion_smoothed_eye_x) * smartinversion_lerp_factor
lerp_factor = 0.2
if self.smartinversion_is_inverted:
if self.eye_id == recessive_eye:
self.smartinversion_smoothed_eye_x += (-tracked_eye_x - self.smartinversion_smoothed_eye_x) * lerp_factor
else:
self.smartinversion_smoothed_eye_x += (tracked_eye_x - self.smartinversion_smoothed_eye_x) * lerp_factor
self.smartinversion_smoothing_progress = max(self.smartinversion_smoothing_progress - self.settings.gui_smartinversion_smoothing_rate, 0)
out_x = self.smartinversion_smoothed_eye_x"""
out_x = self.smartinversion_smoothed_eye_x
#Logic if inversion is active, but smoothing is not active
if self.smartinversion_is_inverted and self.eye_id == recessive_eye:
elif self.smartinversion_is_inverted and self.eye_id == recessive_eye:
out_x = -tracked_eye_x
#Limits the maximum allowed inwards rotation if detected as cross-eyed

View File

@ -83,7 +83,6 @@ def eyetrack_settings_config():
#Smart Inversion Tracking
gui_smartinversion_enabled=False,
gui_smartinversion_select_right=True,
gui_smartinversion_thresh=0.4,
gui_smartinversion_frame_count=10,
gui_smartinversion_smoothing_rate=0.025,
gui_smartinversion_minthresh=0.3,