mirror of
https://github.com/EyeTrackVR/EyeTrackVR.git
synced 2025-11-04 14:39:42 +08:00
split osc cal and value filter to own file
This commit is contained in:
parent
c0004eec3f
commit
a7e9f007a6
@ -56,6 +56,7 @@ import timeit
|
|||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
|
|
||||||
|
from osc_calibrate_filter import *
|
||||||
|
|
||||||
class InformationOrigin(Enum):
|
class InformationOrigin(Enum):
|
||||||
RANSAC = 1
|
RANSAC = 1
|
||||||
@ -76,7 +77,6 @@ class EyeInformation:
|
|||||||
lowb = np.array(0)
|
lowb = np.array(0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def run_once(f):
|
def run_once(f):
|
||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args, **kwargs):
|
||||||
if not wrapper.has_run:
|
if not wrapper.has_run:
|
||||||
@ -93,93 +93,6 @@ async def delayed_setting_change(setting, value):
|
|||||||
if sys.platform.startswith("win"):
|
if sys.platform.startswith("win"):
|
||||||
PlaySound('Audio/compleated.wav', SND_FILENAME | SND_ASYNC)
|
PlaySound('Audio/compleated.wav', SND_FILENAME | SND_ASYNC)
|
||||||
|
|
||||||
def cal_osc(self, cx, cy):
|
|
||||||
if self.eye_id == "EyeId.RIGHT":
|
|
||||||
flipx = self.settings.gui_flip_x_axis_right
|
|
||||||
else:
|
|
||||||
flipx = self.settings.gui_flip_x_axis_left
|
|
||||||
if self.calibration_frame_counter == 0:
|
|
||||||
self.calibration_frame_counter = None
|
|
||||||
self.xoff = cx
|
|
||||||
self.yoff = cy
|
|
||||||
self.now_mode = self.cv_mode[0]
|
|
||||||
self.response_list = []
|
|
||||||
self.response_max = 0
|
|
||||||
if sys.platform.startswith("win"):
|
|
||||||
PlaySound('Audio/compleated.wav', SND_FILENAME | SND_ASYNC)
|
|
||||||
elif self.calibration_frame_counter != None:
|
|
||||||
self.settings.gui_recenter_eyes = False
|
|
||||||
if cx > self.xmax:
|
|
||||||
self.xmax = cx
|
|
||||||
if cx < self.xmin:
|
|
||||||
self.xmin = cx
|
|
||||||
if cy > self.ymax:
|
|
||||||
self.ymax = cy
|
|
||||||
if cy < self.ymin:
|
|
||||||
self.ymin = cy
|
|
||||||
self.calibration_frame_counter -= 1
|
|
||||||
if self.settings.gui_recenter_eyes == True:
|
|
||||||
self.xoff = cx
|
|
||||||
self.yoff = cy
|
|
||||||
if self.ts == 0:
|
|
||||||
self.settings.gui_recenter_eyes = False
|
|
||||||
if sys.platform.startswith("win"):
|
|
||||||
PlaySound('Audio/compleated.wav', SND_FILENAME | SND_ASYNC)
|
|
||||||
else:
|
|
||||||
self.ts = self.ts - 1
|
|
||||||
else:
|
|
||||||
self.ts = 10
|
|
||||||
|
|
||||||
try:
|
|
||||||
xl = float(
|
|
||||||
(cx - self.xoff) / (self.xmax - self.xoff)
|
|
||||||
)
|
|
||||||
xr = float(
|
|
||||||
(cx - self.xoff) / (self.xmin - self.xoff)
|
|
||||||
)
|
|
||||||
yu = float(
|
|
||||||
(cy - self.yoff) / (self.ymin - self.yoff)
|
|
||||||
)
|
|
||||||
yd = float(
|
|
||||||
(cy - self.yoff) / (self.ymax - self.yoff)
|
|
||||||
)
|
|
||||||
|
|
||||||
out_x = 0
|
|
||||||
out_y = 0
|
|
||||||
if self.settings.gui_flip_y_axis: # check config on flipped values settings and apply accordingly
|
|
||||||
if yd >= 0:
|
|
||||||
out_y = max(0.0, min(1.0, yd))
|
|
||||||
if yu > 0:
|
|
||||||
out_y = -abs(max(0.0, min(1.0, yu)))
|
|
||||||
else:
|
|
||||||
if yd >= 0:
|
|
||||||
out_y = -abs(max(0.0, min(1.0, yd)))
|
|
||||||
if yu > 0:
|
|
||||||
out_y = max(0.0, min(1.0, yu))
|
|
||||||
|
|
||||||
if flipx: #TODO Check for working function
|
|
||||||
if xr >= 0:
|
|
||||||
out_x = -abs(max(0.0, min(1.0, xr)))
|
|
||||||
if xl > 0:
|
|
||||||
out_x = max(0.0, min(1.0, xl))
|
|
||||||
else:
|
|
||||||
if xr >= 0:
|
|
||||||
out_x = max(0.0, min(1.0, xr))
|
|
||||||
if xl > 0:
|
|
||||||
out_x = -abs(max(0.0, min(1.0, xl)))
|
|
||||||
except:
|
|
||||||
print("[ERROR] Eye Calibration Invalid!")
|
|
||||||
try:
|
|
||||||
noisy_point = np.array([float(out_x), float(out_y)]) # fliter our values with a One Euro Filter
|
|
||||||
point_hat = self.one_euro_filter(noisy_point)
|
|
||||||
out_x = point_hat[0]
|
|
||||||
out_y = point_hat[1]
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
return out_x, out_y
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#HSF \/
|
#HSF \/
|
||||||
|
|
||||||
# cache param
|
# cache param
|
||||||
|
|||||||
89
EyeTrackApp/osc_calibrate_filter.py
Normal file
89
EyeTrackApp/osc_calibrate_filter.py
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
import sys
|
||||||
|
if sys.platform.startswith("win"):
|
||||||
|
from winsound import PlaySound, SND_FILENAME, SND_ASYNC
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
def cal_osc(self, cx, cy):
|
||||||
|
if self.eye_id == "EyeId.RIGHT":
|
||||||
|
flipx = self.settings.gui_flip_x_axis_right
|
||||||
|
else:
|
||||||
|
flipx = self.settings.gui_flip_x_axis_left
|
||||||
|
if self.calibration_frame_counter == 0:
|
||||||
|
self.calibration_frame_counter = None
|
||||||
|
self.xoff = cx
|
||||||
|
self.yoff = cy
|
||||||
|
self.now_mode = self.cv_mode[0]
|
||||||
|
self.response_list = []
|
||||||
|
self.response_max = 0
|
||||||
|
if sys.platform.startswith("win"):
|
||||||
|
PlaySound('Audio/compleated.wav', SND_FILENAME | SND_ASYNC)
|
||||||
|
elif self.calibration_frame_counter != None:
|
||||||
|
self.settings.gui_recenter_eyes = False
|
||||||
|
if cx > self.xmax:
|
||||||
|
self.xmax = cx
|
||||||
|
if cx < self.xmin:
|
||||||
|
self.xmin = cx
|
||||||
|
if cy > self.ymax:
|
||||||
|
self.ymax = cy
|
||||||
|
if cy < self.ymin:
|
||||||
|
self.ymin = cy
|
||||||
|
self.calibration_frame_counter -= 1
|
||||||
|
if self.settings.gui_recenter_eyes == True:
|
||||||
|
self.xoff = cx
|
||||||
|
self.yoff = cy
|
||||||
|
if self.ts == 0:
|
||||||
|
self.settings.gui_recenter_eyes = False
|
||||||
|
if sys.platform.startswith("win"):
|
||||||
|
PlaySound('Audio/compleated.wav', SND_FILENAME | SND_ASYNC)
|
||||||
|
else:
|
||||||
|
self.ts = self.ts - 1
|
||||||
|
else:
|
||||||
|
self.ts = 10
|
||||||
|
|
||||||
|
try:
|
||||||
|
xl = float(
|
||||||
|
(cx - self.xoff) / (self.xmax - self.xoff)
|
||||||
|
)
|
||||||
|
xr = float(
|
||||||
|
(cx - self.xoff) / (self.xmin - self.xoff)
|
||||||
|
)
|
||||||
|
yu = float(
|
||||||
|
(cy - self.yoff) / (self.ymin - self.yoff)
|
||||||
|
)
|
||||||
|
yd = float(
|
||||||
|
(cy - self.yoff) / (self.ymax - self.yoff)
|
||||||
|
)
|
||||||
|
|
||||||
|
out_x = 0
|
||||||
|
out_y = 0
|
||||||
|
if self.settings.gui_flip_y_axis: # check config on flipped values settings and apply accordingly
|
||||||
|
if yd >= 0:
|
||||||
|
out_y = max(0.0, min(1.0, yd))
|
||||||
|
if yu > 0:
|
||||||
|
out_y = -abs(max(0.0, min(1.0, yu)))
|
||||||
|
else:
|
||||||
|
if yd >= 0:
|
||||||
|
out_y = -abs(max(0.0, min(1.0, yd)))
|
||||||
|
if yu > 0:
|
||||||
|
out_y = max(0.0, min(1.0, yu))
|
||||||
|
|
||||||
|
if flipx: #TODO Check for working function
|
||||||
|
if xr >= 0:
|
||||||
|
out_x = -abs(max(0.0, min(1.0, xr)))
|
||||||
|
if xl > 0:
|
||||||
|
out_x = max(0.0, min(1.0, xl))
|
||||||
|
else:
|
||||||
|
if xr >= 0:
|
||||||
|
out_x = max(0.0, min(1.0, xr))
|
||||||
|
if xl > 0:
|
||||||
|
out_x = -abs(max(0.0, min(1.0, xl)))
|
||||||
|
except:
|
||||||
|
print("[ERROR] Eye Calibration Invalid!")
|
||||||
|
try:
|
||||||
|
noisy_point = np.array([float(out_x), float(out_y)]) # fliter our values with a One Euro Filter
|
||||||
|
point_hat = self.one_euro_filter(noisy_point)
|
||||||
|
out_x = point_hat[0]
|
||||||
|
out_y = point_hat[1]
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
return out_x, out_y
|
||||||
Loading…
Reference in New Issue
Block a user