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
@ -220,7 +220,7 @@ class EyeTrackSettingsConfig(BaseModel):
|
|||||||
#SmartInversionTracking
|
#SmartInversionTracking
|
||||||
gui_smartinversion_enabled: bool = False
|
gui_smartinversion_enabled: bool = False
|
||||||
gui_smartinversion_select_right: bool = True
|
gui_smartinversion_select_right: bool = True
|
||||||
gui_smartinversion_thresh: float = 0.5
|
gui_smartinversion_thresh: float = 0.25
|
||||||
|
|
||||||
|
|
||||||
class EyeTrackConfig(BaseModel):
|
class EyeTrackConfig(BaseModel):
|
||||||
|
|||||||
@ -29,6 +29,7 @@ import time
|
|||||||
from enum import IntEnum
|
from enum import IntEnum
|
||||||
from utils.misc_utils import PlaySound, SND_FILENAME, SND_ASYNC, resource_path
|
from utils.misc_utils import PlaySound, SND_FILENAME, SND_ASYNC, resource_path
|
||||||
from utils.eye_falloff import velocity_falloff
|
from utils.eye_falloff import velocity_falloff
|
||||||
|
from utils.smart_inversion import smart_inversion
|
||||||
import socket
|
import socket
|
||||||
import struct
|
import struct
|
||||||
import threading
|
import threading
|
||||||
@ -335,6 +336,9 @@ class cal:
|
|||||||
var.past_x = out_x_mult
|
var.past_x = out_x_mult
|
||||||
var.past_y = out_y_mult
|
var.past_y = out_y_mult
|
||||||
|
|
||||||
|
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)
|
out_x, out_y = velocity_falloff(self, var, out_x, out_y)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
@ -31,7 +31,7 @@ from settings.BaseSettings import BaseSettingsWidget
|
|||||||
from settings.modules.GeneralSettingsModule import GeneralSettingsModule
|
from settings.modules.GeneralSettingsModule import GeneralSettingsModule
|
||||||
from settings.modules.OneEuroSettingsModule import OneEuroSettingsModule
|
from settings.modules.OneEuroSettingsModule import OneEuroSettingsModule
|
||||||
from settings.modules.OSCSettingsModule import OSCSettingsModule
|
from settings.modules.OSCSettingsModule import OSCSettingsModule
|
||||||
from settings.modules.SmartInversionTrackingSettingsModule import SmartInversionSettingsModule
|
from settings.modules.SmartInversionSettingsModule import SmartInversionSettingsModule
|
||||||
|
|
||||||
|
|
||||||
class SettingsWidget(BaseSettingsWidget):
|
class SettingsWidget(BaseSettingsWidget):
|
||||||
|
|||||||
@ -11,16 +11,18 @@ from settings.modules.CommonFieldValidators import try_convert_to_float
|
|||||||
class SmartInversionValidationModule(BaseValidationModel):
|
class SmartInversionValidationModule(BaseValidationModel):
|
||||||
gui_smartinversion_enabled: bool
|
gui_smartinversion_enabled: bool
|
||||||
gui_smartinversion_select_right: bool
|
gui_smartinversion_select_right: bool
|
||||||
gui_smartinversion_thresh: Annotated[str, AfterValidator(try_convert_to_float)]
|
gui_smartinversion_thresh: Annotated[float, AfterValidator(try_convert_to_float)]
|
||||||
|
gui_smartinversion_recessive_difference: Annotated[float, AfterValidator(try_convert_to_float)]
|
||||||
|
|
||||||
class SmartInversionSettingsModule(BaseSettingsModule):
|
class SmartInversionSettingsModule(BaseSettingsModule):
|
||||||
def __init__(self, config, widget_id, **kwargs):
|
def __init__(self, config, widget_id, **kwargs):
|
||||||
super().__init__(config=config, widget_id=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_enabled = f"-gui_smartinversion_enabled{widget_id}-"
|
||||||
self.gui_smartinversion_select_right = f"-gui_smartinversion_select_right{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_thresh = f"-gui_smartinversion_thresh{widget_id}-"
|
||||||
|
|
||||||
|
|
||||||
def get_layout(self):
|
def get_layout(self):
|
||||||
return [
|
return [
|
||||||
[
|
[
|
||||||
@ -34,7 +36,8 @@ class SmartInversionSettingsModule(BaseSettingsModule):
|
|||||||
background_color="#424042",
|
background_color="#424042",
|
||||||
tooltip="Enables Smart Inversion Tracking System",
|
tooltip="Enables Smart Inversion Tracking System",
|
||||||
),
|
),
|
||||||
|
],
|
||||||
|
[
|
||||||
sg.Text("Max. X-Axis Difference", background_color=BACKGROUND_COLOR),
|
sg.Text("Max. X-Axis Difference", background_color=BACKGROUND_COLOR),
|
||||||
sg.InputText(
|
sg.InputText(
|
||||||
self.config.gui_smartinversion_thresh,
|
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