mirror of
https://github.com/EyeTrackVR/EyeTrackVR.git
synced 2025-11-04 14:39:42 +08:00
Initial logic implementation
This commit is contained in:
parent
5221fd3109
commit
9e5f9e183e
@ -218,9 +218,9 @@ class EyeTrackSettingsConfig(BaseModel):
|
||||
gui_use_module: bool = False
|
||||
|
||||
#SmartInversionTracking
|
||||
gui_smartinversion_enabled: bool = False
|
||||
gui_smartinversion_select_right: bool = True
|
||||
gui_smartinversion_thresh: float = 0.5
|
||||
gui_smartinversion_enabled: bool = False
|
||||
gui_smartinversion_select_right: bool = True
|
||||
gui_smartinversion_thresh: float = 0.25
|
||||
|
||||
|
||||
class EyeTrackConfig(BaseModel):
|
||||
|
||||
@ -29,6 +29,7 @@ import time
|
||||
from enum import IntEnum
|
||||
from utils.misc_utils import PlaySound, SND_FILENAME, SND_ASYNC, resource_path
|
||||
from utils.eye_falloff import velocity_falloff
|
||||
from utils.smart_inversion import smart_inversion
|
||||
import socket
|
||||
import struct
|
||||
import threading
|
||||
@ -335,7 +336,10 @@ class cal:
|
||||
var.past_x = out_x_mult
|
||||
var.past_y = out_y_mult
|
||||
|
||||
out_x, out_y = velocity_falloff(self, var, out_x, out_y)
|
||||
if(self.settings.gui_smartinversion_enabled):
|
||||
out_x, out_y = smart_inversion(self,var, out_x, out_y)
|
||||
else:
|
||||
out_x, out_y = velocity_falloff(self, var, out_x, out_y)
|
||||
|
||||
try:
|
||||
noisy_point = np.array([float(out_x), float(out_y)]) # fliter our values with a One Euro Filter
|
||||
|
||||
@ -31,7 +31,7 @@ from settings.BaseSettings import BaseSettingsWidget
|
||||
from settings.modules.GeneralSettingsModule import GeneralSettingsModule
|
||||
from settings.modules.OneEuroSettingsModule import OneEuroSettingsModule
|
||||
from settings.modules.OSCSettingsModule import OSCSettingsModule
|
||||
from settings.modules.SmartInversionTrackingSettingsModule import SmartInversionSettingsModule
|
||||
from settings.modules.SmartInversionSettingsModule import SmartInversionSettingsModule
|
||||
|
||||
|
||||
class SettingsWidget(BaseSettingsWidget):
|
||||
|
||||
@ -9,17 +9,19 @@ from settings.modules.CommonFieldValidators import try_convert_to_float
|
||||
|
||||
|
||||
class SmartInversionValidationModule(BaseValidationModel):
|
||||
gui_smartinversion_enabled: bool
|
||||
gui_smartinversion_select_right: bool
|
||||
gui_smartinversion_thresh: Annotated[str, AfterValidator(try_convert_to_float)]
|
||||
|
||||
gui_smartinversion_enabled: bool
|
||||
gui_smartinversion_select_right: bool
|
||||
gui_smartinversion_thresh: Annotated[float, AfterValidator(try_convert_to_float)]
|
||||
gui_smartinversion_recessive_difference: Annotated[float, AfterValidator(try_convert_to_float)]
|
||||
|
||||
class SmartInversionSettingsModule(BaseSettingsModule):
|
||||
def __init__(self, config, widget_id, **kwargs):
|
||||
super().__init__(config=config, widget_id=widget_id, **kwargs)
|
||||
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}-"
|
||||
|
||||
|
||||
def get_layout(self):
|
||||
return [
|
||||
@ -34,7 +36,8 @@ class SmartInversionSettingsModule(BaseSettingsModule):
|
||||
background_color="#424042",
|
||||
tooltip="Enables Smart Inversion Tracking System",
|
||||
),
|
||||
|
||||
],
|
||||
[
|
||||
sg.Text("Max. X-Axis Difference", background_color=BACKGROUND_COLOR),
|
||||
sg.InputText(
|
||||
self.config.gui_smartinversion_thresh,
|
||||
48
EyeTrackApp/utils/smart_inversion.py
Normal file
48
EyeTrackApp/utils/smart_inversion.py
Normal file
@ -0,0 +1,48 @@
|
||||
from eye import EyeId
|
||||
from utils.misc_utils import clamp
|
||||
|
||||
inverted_frames = int
|
||||
cleared_frames = int
|
||||
|
||||
def smart_inversion(self, var, out_x, out_y):
|
||||
|
||||
#Updates eye positions with latest
|
||||
if self.eye_id == EyeId.LEFT:
|
||||
var.l_eye_x = out_x
|
||||
var.left_y = out_y
|
||||
|
||||
if self.eye_id == EyeId.RIGHT:
|
||||
var.r_eye_x = out_x
|
||||
var.right_y = out_y
|
||||
|
||||
#Checks if eyes are inverted
|
||||
if (var.l_eye_x > 0 and var.r_eye_x < 0) and (abs(var.l_eye_x - var.r_eye_x) > self.settings.gui_smartinversion_thresh):
|
||||
is_inverted = True
|
||||
else:
|
||||
is_inverted = False
|
||||
|
||||
#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
|
||||
else:
|
||||
tracked_eye_x = var.l_eye_x
|
||||
tracked_eye_y = var.left_y
|
||||
recessive_eye = EyeId.RIGHT
|
||||
|
||||
out_x = tracked_eye_x
|
||||
out_y = tracked_eye_y
|
||||
|
||||
#If eyes are inverted, and eye being processed is recessive, invert x value.
|
||||
if self.eye_id == recessive_eye:
|
||||
if is_inverted:
|
||||
out_x = -tracked_eye_x
|
||||
else:
|
||||
out_x = tracked_eye_x
|
||||
else:
|
||||
out_x = tracked_eye_x
|
||||
|
||||
out_y = tracked_eye_y
|
||||
|
||||
return out_x, out_y
|
||||
Loading…
Reference in New Issue
Block a user