new blink algo (almost done) bug fixes, small perf improvement?

This commit is contained in:
Prohurtz 2023-07-25 20:27:57 -05:00
parent 09bf6737a2
commit a6a8991a61
7 changed files with 106 additions and 28 deletions

View File

@ -166,6 +166,7 @@ class EyeProcessor:
self.prev_x_list = []
self.prev_y_list = []
self.blink_list = []
self.ran_blink_check_for_file = True
self.bd_blink = False
self.current_algo = EyeInfoOrigin.HSRAC
@ -253,10 +254,16 @@ class EyeProcessor:
pass
def UPDATE(self):
if self.settings.gui_RANSACBLINK and self.eyeopen == 0.0:
pass
else:
self.eyeopen = 0.9
if self.settings.gui_BLINK:
self.eyeopen = BLINK(self)
if self.settings.gui_IBO and self.eyeopen != 0.0:
if self.settings.gui_IBO and self.eyeopen != 0.0: #TODO make ransac blink it's pwn self var to rid of this non-sense
self.eyeopen = self.ibo.intense(
self.rawx,
self.rawy,
@ -268,9 +275,11 @@ class EyeProcessor:
self.eyeopen < self.settings.ibo_fully_close_eye_threshold
): # threshold so the eye fully closes
self.eyeopen = 0.0
if self.bd_blink == True:
pass
if self.settings.gui_IBO and self.settings.gui_BLINK and self.eyeopen != 0.0:
ibo = self.ibo.intense(
self.rawx,
@ -287,7 +296,7 @@ class EyeProcessor:
self.eyeopen = ibo
if len(self.prev_y_list) >= 200: # "lock" eye when close/blink IN TESTING
if len(self.prev_y_list) >= 200: # "lock" eye when close/blink IN TESTING, kinda broke
self.prev_y_list.pop(0)
self.prev_y_list.append(self.out_y)
else:
@ -297,9 +306,11 @@ class EyeProcessor:
blink_vec = min(abs(self.eyeopen - self.past_blink), 1) #clamp to 1
if blink_vec >= 0.1 or blink_vec == 0.0 and (self.out_y - self.prev_y) < 0.0:
#if blink_vec >= 0.1 or blink_vec == 0.0 and (self.out_y - self.prev_y) < 0.0:
# self.out_x = sum(self.prev_x_list) / len(self.prev_x_list)
self.out_y = sum(self.prev_y_list) / len(self.prev_y_list)
# print('AVG', self.out_y, len(self.prev_y_list))
self.past_blink = self.eyeopen
self.prev_x = self.out_x
self.prev_y = self.out_y
@ -316,7 +327,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, self.rawx, self.rawy, self.eyeopen = self.er_leap.run(self.current_image_gray) #TODO: make own self var and LEAP toggle
self.thresh = self.current_image_gray.copy()
self.out_x, self.out_y = cal.cal_osc(self, self.rawx, self.rawy)
self.current_algorithm = EyeInfoOrigin.LEAP
@ -352,9 +363,9 @@ class EyeProcessor:
self.current_image_gray
)
self.rawx, self.rawy, self.thresh, ranblink = RANSAC3D(self, True)
if self.settings.gui_RANSACBLINK:
# print("yes", ranblink)
if self.settings.gui_RANSACBLINK: #might be redundant
self.eyeopen = ranblink
# print(self.radius)
# if self.prev_x is None:
# self.prev_x = self.rawx

View File

@ -35,7 +35,7 @@ SETTINGS_RADIO_NAME = "-SETTINGSRADIO-"
ALGO_SETTINGS_RADIO_NAME = "-ALGOSETTINGSRADIO-"
page_url = "https://github.com/RedHawk989/EyeTrackVR/releases/latest"
appversion = "EyeTrackApp 0.2.0 BETA 6"
appversion = "EyeTrackApp 0.2.0 BETA 7"
def main():

View File

@ -6,7 +6,19 @@ import numpy as np
from utils.misc_utils import clamp
from utils.img_utils import safe_crop
from enum import IntEnum
import psutil
import sys
import os
process = psutil.Process(os.getpid()) # set process priority to low
try: # medium chance this does absolutely nothing but eh
sys.getwindowsversion()
except AttributeError:
process.nice(0) # UNIX: 0 low 10 high
process.nice()
else:
process.nice(psutil.BELOW_NORMAL_PRIORITY_CLASS) # Windows
process.nice()
class EyeId(IntEnum):
RIGHT = 0

View File

@ -33,7 +33,18 @@ from enums import EyeLR
from one_euro_filter import OneEuroFilter
from utils.img_utils import safe_crop
from enum import IntEnum
import psutil
import sys
process = psutil.Process(os.getpid()) # set process priority to low
try: # medium chance this does absolutely nothing but eh
sys.getwindowsversion()
except AttributeError:
process.nice(0) # UNIX: 0 low 10 high
process.nice()
else:
process.nice(psutil.BELOW_NORMAL_PRIORITY_CLASS) # Windows
process.nice()
class EyeId(IntEnum):
RIGHT = 0
@ -404,5 +415,5 @@ class IntensityBasedOpeness:
# print(eyevec)
# if eyevec > 0.4:
# print("BLINK LCOK")
# print(eyeopen)
return eyeopen

View File

@ -74,8 +74,8 @@ class LEAP_C(object):
def __init__(self):
onnxruntime.disable_telemetry_events()
# Config variables
self.num_threads = 2 # Number of python threads to use (using ~1 more than needed to acheive wanted fps yeilds lower cpu usage)
self.queue_max_size = 2 # Optimize for best CPU usage, Memory, and Latency. A maxsize is needed to not create a potential memory leak.
self.num_threads = 3 # Number of python threads to use (using ~1 more than needed to acheive wanted fps yeilds lower cpu usage)
self.queue_max_size = 1 # Optimize for best CPU usage, Memory, and Latency. A maxsize is needed to not create a potential memory leak.
self.model_path = 'Models/mommy062023.onnx'
self.interval = 1 # FPS print update rate
self.low_priority = True # set process priority to low

View File

@ -96,13 +96,16 @@ def output_osc(eye_x, eye_y, eye_blink, last_blink, self):
if self.main_config.eye_display_id in [EyeId.RIGHT, EyeId.LEFT]: # we are in single eye mode
se = True
if eye_blink == 0.0:
# print("WE ARE BLINKIN")
if last_blink > 0.2: # when binary blink is on, blinks may be too fast for OSC so we repeat them.
for i in range(5):
self.client.send_message("/tracking/eye/EyesClosedAmount",
float(1 - eye_blink))
eye_blink += 0.02 #TODO finish tuning value
print(eye_blink)
# print(eye_blink, 'osc')
# print(last_blink, time.time(), float(time.time() - last_blink))
last_blink = time.time() - last_blink
else:
self.client.send_message("/tracking/eye/EyesClosedAmount", float(1 - eye_blink))
self.client.send_message("/tracking/eye/LeftRightVec", [float(eye_x), float(eye_y), 1.0, float(eye_x), float(eye_y), 1.0]) # vrc native ET
@ -169,7 +172,7 @@ def output_osc(eye_x, eye_y, eye_blink, last_blink, self):
if not se:
# vrc native ET (z values may need tweaking, they act like a scalar)
self.client.send_message("/tracking/eye/LeftRightVec",[float(self.l_eye_x), float(self.left_y), 0.8, float(self.r_eye_x), float(self.right_y),0.8])
self.client.send_message("/tracking/eye/LeftRightVec",[float(self.l_eye_x), float(self.left_y), 1.0, float(self.r_eye_x), float(self.right_y), 1.0])
class VRChatOSC:

View File

@ -30,13 +30,25 @@ import numpy as np
from enum import IntEnum
from utils.img_utils import safe_crop
from utils.misc_utils import clamp
import os
import psutil
import sys
process = psutil.Process(os.getpid()) # set process priority to low
try: # medium chance this does absolutely nothing but eh
sys.getwindowsversion()
except AttributeError:
process.nice(0) # UNIX: 0 low 10 high
process.nice()
else:
process.nice(psutil.BELOW_NORMAL_PRIORITY_CLASS) # Windows
process.nice()
class EyeId(IntEnum):
RIGHT = 0
LEFT = 1
BOTH = 2
SETTINGS = 3
def ellipse_model(data, y, f):
"""
There is no need to make this process a function, since making the process a function will slow it down a little by calling it.
@ -300,9 +312,11 @@ def RANSAC3D(self, hsrac_en):
except:
f = True
csy = newFrame2.shape[0]
csx = newFrame2.shape[1]
if hsrac_en:
csy = newFrame2.shape[0]
csx = newFrame2.shape[1]
if ranf:
cx = self.rawx
@ -322,22 +336,49 @@ def RANSAC3D(self, hsrac_en):
# if abs(perscalarw-perscalarh) >= 0.2: # TODO setting
# blink = 0.0
if len(self.blink_list) >= 10000: # self calibrate ransac blink IN TESTING
self.blink_list.pop(0)
self.blink_list.append(abs(perscalarw-perscalarh))
if self.settings.gui_RANSACBLINK:
else:
# print('app')
self.blink_list.append(abs(perscalarw-perscalarh))
if self.ran_blink_check_for_file:
if self.eye_id in [EyeId.LEFT]:
file_path = 'RANSAC_blink_LEFT.cfg'
if self.eye_id in [EyeId.RIGHT]:
file_path = 'RANSAC_blink_RIGHT.cfg'
else:
file_path = 'RANSAC_blink_RIGHT.cfg'
if os.path.exists(file_path):
with open(file_path, 'r') as file:
self.blink_list = [float(line.strip()) for line in file]
else:
print(f"\033[93m[INFO] RANSAC Blink Config '{file_path}' not found. Waiting for calibration.\033[0m")
self.ran_blink_check_for_file = False
if len(self.blink_list) == 10000: # self calibrate ransac blink IN TESTING
if self.eye_id in [EyeId.LEFT]:
with open("RANSAC_BLINK_LEFT.cfg", 'w') as file:
for item in self.blink_list:
file.write(str(item) + '\n')
if self.eye_id in [EyeId.RIGHT]:
with open("RANSAC_BLINK_RIGHT.cfg", 'w') as file:
for item in self.blink_list:
file.write(str(item) + '\n')
print('SAVE')
# self.blink_list.pop(0)
self.blink_list.append(abs(perscalarw-perscalarh))
elif len(self.blink_list) < 10000:
self.blink_list.append(abs(perscalarw-perscalarh))
if abs(perscalarw-perscalarh) >= np.percentile(
self.blink_list, 94
):
blink = 0.0
# print(np.percentile(blink_list, 80), abs(perscalarw-perscalarh))
# print(len(self.blink_list))
if abs(perscalarw-perscalarh) >= np.percentile(
self.blink_list, 94
):
blink = 0.0
print('blink')
try:
cv2.drawContours(self.current_image_gray, contours, -1, (255, 0, 0), 1) # TODO: fix visualizations with HSRAC