Set eye to center when beginning inversion, remove smoothing

This commit is contained in:
Blabzillaweasel 2025-02-09 13:17:37 +13:00
parent f8b9b7305c
commit 8939c020ff
4 changed files with 44 additions and 22 deletions

View File

@ -229,6 +229,7 @@ class EyeTrackSettingsConfig(BaseModel):
gui_smartinversion_frame_count: int = 30
gui_smartinversion_smoothing_rate: float = 0.025
gui_smartinversion_minthresh: float = 0.3
gui_smartinversion_rotation_clamp: float = 1.0
class EyeTrackConfig(BaseModel):
version: int = 1

View File

@ -15,6 +15,7 @@ class SmartInversionValidationModule(BaseValidationModel):
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)]
gui_smartinversion_rotation_clamp: Annotated[float, AfterValidator(try_convert_to_float)]
class SmartInversionSettingsModule(BaseSettingsModule):
def __init__(self, config, widget_id, **kwargs):
@ -26,6 +27,7 @@ class SmartInversionSettingsModule(BaseSettingsModule):
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}"
self.gui_smartinversion_rotation_clamp =f"-gui_smartinversion_rotation_clamp{widget_id}-"
@ -107,4 +109,16 @@ class SmartInversionSettingsModule(BaseSettingsModule):
)
),
],
[
sg.Text("Maximum allowed cross-eye", background_color=BACKGROUND_COLOR),
sg.InputText(
self.config.gui_smartinversion_rotation_clamp,
key=self.gui_smartinversion_rotation_clamp,
size=(0, 10),
tooltip=(
"Defines the maximum inwards rotation that is output when cross-eyed."
"\n0 = will only look straight ahead \n0.5 = will go a little bit cross-eyed \n1 = maximum hurr durr "
)
),
],
]

View File

@ -26,6 +26,20 @@ def smart_inversion(self, var, out_x, out_y):
var.r_eye_x = out_x
var.right_y = out_y
#Determines which eye is being tracked based off selection and sets values accordingly
if self.settings.gui_smartinversion_select_right:
tracked_eye_x = var.r_eye_x
tracked_eye_y = var.right_y
recessive_eye = EyeId.LEFT
dominant_eye = EyeId.RIGHT
else:
tracked_eye_x = var.l_eye_x
tracked_eye_y = var.left_y
recessive_eye = EyeId.RIGHT
dominant_eye = EyeId.LEFT
#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):
self.smartinversion_inverted_frame_count = min(self.smartinversion_inverted_frame_count + 1, self.settings.gui_smartinversion_frame_count)
@ -34,6 +48,7 @@ def smart_inversion(self, var, out_x, out_y):
if not self.smartinversion_is_inverted:
self.smartinversion_is_inverted = True
self.smartinversion_normal_frame_count = 0
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.
@ -50,42 +65,33 @@ def smart_inversion(self, var, out_x, out_y):
self.smartinversion_inverted_frame_count = 0
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
#Determines which eye is being tracked based off selection and sets values accordingly
if self.settings.gui_smartinversion_select_right:
tracked_eye_x = var.r_eye_x
tracked_eye_y = var.right_y
recessive_eye = EyeId.LEFT
dominant_eye = EyeId.RIGHT
else:
tracked_eye_x = var.l_eye_x
tracked_eye_y = var.left_y
recessive_eye = EyeId.RIGHT
dominant_eye = EyeId.LEFT
out_x = tracked_eye_x
out_y = tracked_eye_y
#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 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
else:
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
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
elif self.smartinversion_is_inverted and self.eye_id == recessive_eye:
if self.smartinversion_is_inverted and self.eye_id == recessive_eye:
out_x = -tracked_eye_x
out_y = tracked_eye_y
#Limits the maximum allowed inwards rotation if detected as cross-eyed
if self.smartinversion_is_inverted:
if self.eye_id == EyeId.LEFT:
out_x = min(out_x, self.settings.gui_smartinversion_rotation_clamp)
else:
out_x = max(out_x, -self.settings.gui_smartinversion_rotation_clamp)
return out_x, out_y

View File

@ -87,6 +87,7 @@ def eyetrack_settings_config():
gui_smartinversion_frame_count=10,
gui_smartinversion_smoothing_rate=0.025,
gui_smartinversion_minthresh=0.3,
gui_smartinversion_rotation_clamp=1.0,
)