mirror of
https://github.com/EyeTrackVR/EyeTrackVR.git
synced 2025-09-26 23:09:28 +08:00
Merge pull request #129 from Fracas42/v2.0-save-leap-calibration
feat: LEAP save calibration
This commit is contained in:
commit
52956eda87
@ -56,6 +56,9 @@ class EyeTrackCameraConfig(BaseModel):
|
||||
calib_YOFF: Union[float, None] = None
|
||||
calibration_points: List[List[Union[float, None]]] = []
|
||||
calibration_points_3d: List[List[Union[float, None]]] = []
|
||||
leap_calibration_percentile_90: float = 0
|
||||
leap_calibration_percentile_2: float = 0
|
||||
leap_calibrated: bool = False
|
||||
|
||||
|
||||
def update_capture_source(self, new_camera_address: str):
|
||||
|
@ -319,7 +319,7 @@ class EyeProcessor:
|
||||
self.rawx,
|
||||
self.rawy,
|
||||
self.eyeopen,
|
||||
) = self.er_leap.run(self.current_image_gray, self.current_image_gray_clean, self.calibration_frame_counter, self.settings.leap_calibration_samples)
|
||||
) = self.er_leap.run(self.current_image_gray, self.current_image_gray_clean, self.calibration_frame_counter)
|
||||
|
||||
if len(self.prev_y_list) >= 100: # "lock" eye when close/blink IN TESTING, kinda broke
|
||||
self.prev_y_list.pop(0)
|
||||
@ -391,7 +391,7 @@ class EyeProcessor:
|
||||
def LEAPM(self):
|
||||
self.thresh = self.current_image_gray.copy()
|
||||
(self.current_image_gray, self.rawx, self.rawy, self.eyeopen,) = self.er_leap.run(
|
||||
self.current_image_gray, self.current_image_gray_clean, self.calibration_frame_counter, self.settings.leap_calibration_samples
|
||||
self.current_image_gray, self.current_image_gray_clean, self.calibration_frame_counter
|
||||
) # TODO: make own self var and LEAP toggle
|
||||
self.thresh = self.current_image_gray.copy()
|
||||
# todo: lorow, fix this as well
|
||||
@ -699,7 +699,7 @@ class EyeProcessor:
|
||||
|
||||
if self.settings.gui_LEAP or self.settings.gui_LEAP_lid:
|
||||
if self.er_leap is None:
|
||||
self.er_leap = External_Run_LEAP()
|
||||
self.er_leap = External_Run_LEAP(self.config, self.baseconfig)
|
||||
algolist[self.settings.gui_LEAP] = self.LEAPM
|
||||
else:
|
||||
if self.er_leap is not None:
|
||||
|
@ -6,6 +6,7 @@ import time
|
||||
import math
|
||||
from queue import Queue
|
||||
import threading
|
||||
from config import EyeTrackCameraConfig, EyeTrackConfig
|
||||
from one_euro_filter import OneEuroFilter
|
||||
import psutil
|
||||
from utils.misc_utils import resource_path
|
||||
@ -42,7 +43,7 @@ def run_onnx_model(queues, session, frame):
|
||||
|
||||
|
||||
class LEAP_C:
|
||||
def __init__(self):
|
||||
def __init__(self, eye_config: EyeTrackCameraConfig, config: EyeTrackConfig):
|
||||
self.last_lid = None
|
||||
self.current_image_gray = None
|
||||
self.current_image_gray_clean = None
|
||||
@ -78,6 +79,8 @@ class LEAP_C:
|
||||
self.old_per = 0.0
|
||||
self.delta_per_neg = 0.0
|
||||
self.ort_session1 = onnxruntime.InferenceSession(self.model_path, opts, providers=["CPUExecutionProvider"])
|
||||
self.eye_config: EyeTrackCameraConfig = eye_config
|
||||
self.config: EyeTrackConfig = config
|
||||
|
||||
for i in range(self.num_threads):
|
||||
thread = threading.Thread(
|
||||
@ -111,21 +114,22 @@ class LEAP_C:
|
||||
d2 = math.dist(pre_landmark[2], pre_landmark[4])
|
||||
d = (d1 + d2) / 2
|
||||
|
||||
# if len(self.openlist) > 0 and d >= np.percentile(self.openlist, 80) and len(self.openlist) < self.calibration_samples:
|
||||
# self.maxlist.append(d)
|
||||
|
||||
|
||||
normal_open = np.percentile(self.openlist, 90) if len(self.openlist) >= 10 else 0.8
|
||||
|
||||
if self.calib == 0:
|
||||
self.openlist = []
|
||||
self.eye_config.leap_calibrated = False
|
||||
|
||||
if len(self.openlist) < self.calibration_samples:
|
||||
if not self.eye_config.leap_calibrated:
|
||||
self.openlist.append(d)
|
||||
self.eye_config.leap_calibration_percentile_90 = np.percentile(self.openlist, 90) if len(self.openlist) >= 10 else 0.8
|
||||
self.eye_config.leap_calibration_percentile_2 = np.percentile(self.openlist, 2) - self.eye_config.leap_calibration_percentile_90
|
||||
if len(self.openlist) >= self.config.settings.leap_calibration_samples:
|
||||
self.eye_config.leap_calibrated = True
|
||||
self.config.save()
|
||||
print(f"[INFO] {'Left' if self.eye_config is self.config.left_eye else 'Right'} eye calibrated")
|
||||
|
||||
try:
|
||||
if len(self.openlist) > 0:
|
||||
per = (d - normal_open) / (np.percentile(self.openlist, 2) - normal_open)
|
||||
if len(self.openlist) > 0 or self.eye_config.leap_calibrated:
|
||||
per = (d - self.eye_config.leap_calibration_percentile_90) / self.eye_config.leap_calibration_percentile_2
|
||||
per = 1 - per
|
||||
per = np.clip(per, 0.0, 1.0)
|
||||
else:
|
||||
@ -150,13 +154,12 @@ class LEAP_C:
|
||||
|
||||
|
||||
class External_Run_LEAP:
|
||||
def __init__(self):
|
||||
self.algo = LEAP_C()
|
||||
def __init__(self, eye_config: EyeTrackCameraConfig, config: EyeTrackConfig):
|
||||
self.algo = LEAP_C(eye_config, config)
|
||||
|
||||
def run(self, current_image_gray, current_image_gray_clean, calib, calibration_samples):
|
||||
def run(self, current_image_gray, current_image_gray_clean, calib):
|
||||
self.algo.current_image_gray = current_image_gray
|
||||
self.algo.current_image_gray_clean = current_image_gray_clean
|
||||
self.algo.calib = calib
|
||||
self.algo.calibration_samples = calibration_samples
|
||||
img, x, y, per = self.algo.leap_run()
|
||||
return img, x, y, per
|
||||
|
Loading…
Reference in New Issue
Block a user