diff --git a/EyeTrackApp/blink.py b/EyeTrackApp/blink.py index 9be8138..d00303a 100644 --- a/EyeTrackApp/blink.py +++ b/EyeTrackApp/blink.py @@ -2,6 +2,10 @@ import numpy as np def BLINK(self): + if self.blink_clear == True: + self.max_ints = [] + self.max_int = 0 + intensity = np.sum(self.current_image_gray_clean) self.frames = self.frames + 1 diff --git a/EyeTrackApp/eye_processor.py b/EyeTrackApp/eye_processor.py index a776aa2..1e3c8c7 100644 --- a/EyeTrackApp/eye_processor.py +++ b/EyeTrackApp/eye_processor.py @@ -145,6 +145,7 @@ class EyeProcessor: self.xmin = 69420 self.ymax = -69420 self.ymin = 69420 + self.blink_clear = False self.cct = 300 self.cccs = False self.ts = 10 @@ -179,7 +180,7 @@ class EyeProcessor: self.prev_y = None self.bd_blink = False self.current_algo = InformationOrigin.HSRAC - + try: min_cutoff = float(self.settings.gui_min_cutoff) # 0.0004 @@ -258,6 +259,7 @@ class EyeProcessor: def UPDATE(self): + # print(self.blink_clear) if self.settings.gui_BLINK: self.eyeopen = BLINK(self) @@ -496,9 +498,3 @@ class EyeProcessor: self.ALGOSELECT() #run our algos in priority order set in settings self.UPDATE() - - - - - - diff --git a/EyeTrackApp/hsrac.py b/EyeTrackApp/hsrac.py index 5494b6f..ad3a139 100644 --- a/EyeTrackApp/hsrac.py +++ b/EyeTrackApp/hsrac.py @@ -112,9 +112,9 @@ def fit_rotated_ellipse_ransac(data: np.ndarray, sfc: np.random.Generator, iter_ np.matmul(dm_rng_swap_trans, dm_rng_swap, out=dm_rng_5x5) # np.linalg.solve(np.matmul(dm_rng_swap_trans, dm_rng_swap), dm_rng_swap_trans) # solve is slow https://github.com/bogovicj/JaneliaMLCourse/issues/1 - # _umath_linalg.inv(dm_rng_5x5, signature='d->d', - # extobj=inv_ext, out=dm_rng_5x5) - dm_rng_5x5 = np.linalg.pinv(dm_rng_5x5) + _umath_linalg.inv(dm_rng_5x5, signature='d->d', + extobj=inv_ext, out=dm_rng_5x5) + #dm_rng_5x5 = np.linalg.pinv(dm_rng_5x5) np.matmul(dm_rng_5x5, dm_rng_swap_trans, out=dm_rng_p5smp) np.matmul(dm_rng_p5smp, dm_rng_six, out=dm_rng_p_npaxis) diff --git a/EyeTrackApp/intensity_eye_open.py b/EyeTrackApp/intensity_eye_open.py index f3ff508..24be5d6 100644 --- a/EyeTrackApp/intensity_eye_open.py +++ b/EyeTrackApp/intensity_eye_open.py @@ -3,6 +3,7 @@ import time import os import cv2 from enums import EyeLR +from one_euro_filter import OneEuroFilter from utils.img_utils import safe_crop #higher intensity means more closed/ more white/less pupil @@ -85,6 +86,19 @@ class IntensityBasedOpeness: self.img_roi = np.zeros(3, dtype=np.int32) self.now_roi = np.zeros(3, dtype=np.int32) self.prev_val = 0.5 + # try: + # min_cutoff = float(self.settings.gui_min_cutoff) # 0.0004 + # beta = float(self.settings.gui_speed_coefficient) # 0.9 + # except: + print('\033[93m[WARN] OneEuroFilter values must be a legal number.\033[0m') + min_cutoff = 0.0004 + beta = 0.9 + noisy_point = np.array([1, 1]) + self.one_euro_filter = OneEuroFilter( + noisy_point, + min_cutoff=min_cutoff, + beta=beta + ) def check(self, frameshape): @@ -156,10 +170,10 @@ class IntensityBasedOpeness: lower_y = max(int_y - 15, 0) # frame_crop = frame[lower_y:upper_y, lower_x:upper_x] - frame_crop = safe_crop(frame, lower_x, lower_y, upper_x, upper_y, 1) + # frame_crop = safe_crop(frame, lower_x, lower_y, upper_x, upper_y, 1) #ret_, th = cv2.threshold(frame_crop, 80, 1.0, cv2.THRESH_BINARY_INV, dst=frame_crop) - - ret, f = cv2.threshold(frame, 80, 255, cv2.THRESH_BINARY) + frame_crop = frame + #ret, f = cv2.threshold(frame, 80, 255, cv2.THRESH_BINARY) # ret, frame_crop = cv2.threshold(frame_crop, 80, 255, cv2.THRESH_BINARY) # The same can be done with cv2.integral, but since there is only one area of the rectangle for which we want to know the total value, there is no advantage in terms of computational complexity. @@ -167,7 +181,8 @@ class IntensityBasedOpeness: avg_color_per_row = np.average(frame_crop, axis=0) avg_color = np.average(avg_color_per_row, axis=0) ar, ag, ab = avg_color - intensity = ar + intensity = int(ar * 8) #higher = closed + #cv2.imshow("IBO", frame_crop) #if cv2.waitKey(1) & 0xFF == ord("q"): # pass @@ -221,7 +236,7 @@ class IntensityBasedOpeness: self.data[int_y, int_x] = intensity # set value changed = True else: - intensitya = max(data_val + 0.02, 1) # if current intensity value is less (more pupil), save that + intensitya = max(data_val + 0.001, 1) # if current intensity value is less (more pupil), save that self.data[int_y, int_x] = intensitya # set value changed = True @@ -232,7 +247,7 @@ class IntensityBasedOpeness: if intensity > self.maxval: # if current intensity value is more (less pupil), save that NOTE: we have the self.maxval = intensity # set value at 0 index else: - intensityd = max(self.maxval - 0.02, 1) # continuously adjust closed intensity, will be set when user blink, used to allow eyes to close when lighting changes + intensityd = max(self.maxval - 0.01, 1) # continuously adjust closed intensity, will be set when user blink, used to allow eyes to close when lighting changes self.maxval = intensityd # set value at 0 index # print(intensityd, intensity) if newval_flg: @@ -260,4 +275,21 @@ class IntensityBasedOpeness: #@filter_eyeopen = (eyeopen + self.prev_val) / 2 self.prev_val = eyeopen + try: + noisy_point = np.array([float(eyeopen), float(eyeopen)]) # fliter our values with a One Euro Filter + point_hat = self.one_euro_filter(noisy_point) + eyeopenx = point_hat[0] + eyeopeny = point_hat[1] + eyeopen = (eyeopenx + eyeopeny) / 2 + # print(eyeopen, eyeopenx, eyeopeny) + except: + pass + if eyeopen - self.prev_val > 100: + print('BLINK') + + eyevec = abs(self.prev_val - eyeopen) + #print(eyevec) + if eyevec > 0.4: + print("BLINK LCOK", eyeopen, eyevec) + print(intensity) return eyeopen diff --git a/EyeTrackApp/osc_calibrate_filter.py b/EyeTrackApp/osc_calibrate_filter.py index 3be9fce..b9a315d 100644 --- a/EyeTrackApp/osc_calibrate_filter.py +++ b/EyeTrackApp/osc_calibrate_filter.py @@ -28,8 +28,10 @@ class cal(): self.config.calib_XMIN = 69420 self.config.calib_YMAX = -69420 self.config.calib_YMIN = 69420 + self.blink_clear = True self.calibration_frame_counter -= 1 elif self.calibration_frame_counter != None: + self.blink_clear = False self.settings.gui_recenter_eyes = False if cx > self.config.calib_XMAX: self.config.calib_XMAX = cx