From 0504e01a9ec28f480ce5a423d6c6d93a2a03d3ae Mon Sep 17 00:00:00 2001 From: PallasNeko <124042774+PallasNeko@users.noreply.github.com> Date: Fri, 10 Feb 2023 20:39:10 +0900 Subject: [PATCH] Fixed Autoradius not working. --- EyeTrackApp/eye_processor.py | 66 ++++++++++++++++++---------- EyeTrackApp/haar_surround_feature.py | 16 ++++--- EyeTrackApp/hsrac.py | 33 ++++++++------ 3 files changed, 75 insertions(+), 40 deletions(-) diff --git a/EyeTrackApp/eye_processor.py b/EyeTrackApp/eye_processor.py index 4d4a5f6..5d2633a 100644 --- a/EyeTrackApp/eye_processor.py +++ b/EyeTrackApp/eye_processor.py @@ -150,9 +150,9 @@ class EyeProcessor: self.camera_model = None self.detector_3d = None - self.camera_model = None - self.detector_3d = None - + self.er_hsf = None + self.er_hsrac = None + self.failed = 0 self.skip_blink_detect = False @@ -234,7 +234,7 @@ class EyeProcessor: rotation_matrix, (cols, rows), borderMode=cv2.BORDER_CONSTANT, - borderValue=(255, 255, 255), + borderValue=(64, 64, 64),#(255, 255, 255), ) return True except: @@ -245,7 +245,8 @@ class EyeProcessor: def HSRACM(self): - cx, cy, thresh, gray_frame, uncropframe = External_Run_HSRACS().run(self.current_image_gray) + # todo: added process to initialise er_hsrac when resolution changes + cx, cy, thresh, gray_frame, uncropframe = self.er_hsrac.run(self.current_image_gray) self.current_image_gray = gray_frame if self.prev_x is None: self.prev_x = cx @@ -267,7 +268,8 @@ class EyeProcessor: # print("EYE MOVED TOO FAST") # self.output_images_and_update(thresh, EyeInformation(InformationOrigin.HSRAC, 0, 0, 0, False)) def HSFM(self): - cx, cy, frame = External_Run_HSF().run(self.current_image_gray) + # todo: added process to initialise er_hsf when resolution changes + cx, cy, frame = self.er_hsf.run(self.current_image_gray) self.eyeopen = intense(cx, cy, self.current_image_gray) out_x, out_y = cal_osc(self, cx, cy) if cx == 0: @@ -326,16 +328,36 @@ class EyeProcessor: self.secondalgo = None self.thirdalgo = None self.fourthalgo = None + algolist = [None, None, None, None, None] + #set algo priorities + + if self.settings.gui_HSF: + if self.er_hsf is None: + self.er_hsf = External_Run_HSF(self.settings.gui_skip_autoradius, self.settings.gui_HSF_radius) + algolist[self.settings.gui_HSFP] = self.HSFM + else: + if self.er_hsf is not None: + self.er_hsf = None + + if self.settings.gui_HSRAC: + if self.er_hsrac is None: + self.er_hsrac = External_Run_HSRACS(self.settings.gui_skip_autoradius, self.settings.gui_HSF_radius) + algolist[self.settings.gui_HSRACP] = self.HSRACM + else: + if self.er_hsrac is not None: + self.er_hsrac = None - if self.settings.gui_HSF and self.settings.gui_HSFP == 1: #I feel like this is super innefficient though it only runs at startup and no solution is coming to me atm - self.firstalgo = self.HSFM - elif self.settings.gui_HSF and self.settings.gui_HSFP == 2: - self.secondalgo = self.HSFM - elif self.settings.gui_HSF and self.settings.gui_HSFP == 3: - self.thirdalgo = self.HSFM - elif self.settings.gui_HSF and self.settings.gui_HSFP == 4: - self.fourthalgo = self.HSFM + _, self.firstalgo, self.secondalgo, self.thirdalgo, self.fourthalgo = algolist + + # if self.settings.gui_HSF and self.settings.gui_HSFP == 1: #I feel like this is super innefficient though it only runs at startup and no solution is coming to me atm + # self.firstalgo = self.HSFM + # elif self.settings.gui_HSF and self.settings.gui_HSFP == 2: + # self.secondalgo = self.HSFM + # elif self.settings.gui_HSF and self.settings.gui_HSFP == 3: + # self.thirdalgo = self.HSFM + # elif self.settings.gui_HSF and self.settings.gui_HSFP == 4: + # self.fourthalgo = self.HSFM if self.settings.gui_RANSAC3D and self.settings.gui_RANSAC3DP == 1: self.firstalgo = self.RANSAC3DM @@ -346,14 +368,14 @@ class EyeProcessor: elif self.settings.gui_RANSAC3D and self.settings.gui_RANSAC3DP == 4: self.fourthalgo = self.RANSAC3DM - if self.settings.gui_HSRAC and self.settings.gui_HSRACP == 1: - self.firstalgo = self.HSRACM - elif self.settings.gui_HSRAC and self.settings.gui_HSRACP == 2: - self.secondalgo = self.HSRACM - elif self.settings.gui_HSRAC and self.settings.gui_HSRACP == 3: - self.thirdalgo = self.HSRACM - elif self.settings.gui_HSRAC and self.settings.gui_HSRACP == 4: - self.fourthalgo = self.HSRACM + # if self.settings.gui_HSRAC and self.settings.gui_HSRACP == 1: + # self.firstalgo = self.HSRACM + # elif self.settings.gui_HSRAC and self.settings.gui_HSRACP == 2: + # self.secondalgo = self.HSRACM + # elif self.settings.gui_HSRAC and self.settings.gui_HSRACP == 3: + # self.thirdalgo = self.HSRACM + # elif self.settings.gui_HSRAC and self.settings.gui_HSRACP == 4: + # self.fourthalgo = self.HSRACM if self.settings.gui_BLOB and self.settings.gui_BLOBP == 1: self.firstalgo = self.BLOBM diff --git a/EyeTrackApp/haar_surround_feature.py b/EyeTrackApp/haar_surround_feature.py index 2e66daf..3104791 100644 --- a/EyeTrackApp/haar_surround_feature.py +++ b/EyeTrackApp/haar_surround_feature.py @@ -602,10 +602,10 @@ class HSF_cls(object): if self.blink_detector.response_len() < blink_init_frames: self.blink_detector.add_response(cv2.mean(cropped_image)[0]) - upper_x = center_x + self.center_correct.center_q1_radius - lower_x = center_x - self.center_correct.center_q1_radius - upper_y = center_y + self.center_correct.center_q1_radius - lower_y = center_y - self.center_correct.center_q1_radius + upper_x = center_x + max(20, radius)#self.center_correct.center_q1_radius + lower_x = center_x - max(20, radius)#self.center_correct.center_q1_radius + upper_y = center_y + max(20, radius)#self.center_correct.center_q1_radius + lower_y = center_y - max(20, radius)#self.center_correct.center_q1_radius self.center_q1.add_response( cv2.mean(safe_crop(gray_frame, lower_x, lower_y, upper_x, upper_y,keepsize=False))[ @@ -702,7 +702,13 @@ class HSF_cls(object): return center_x, center_y, frame class External_Run_HSF(object): - def __init__(self): + def __init__(self, skip_autoradius_flg=False, radius=20): + # temporary code + global skip_autoradius,default_radius + skip_autoradius = skip_autoradius_flg + if skip_autoradius: + default_radius = radius + self.algo = HSF_cls() def run(self, current_image_gray): diff --git a/EyeTrackApp/hsrac.py b/EyeTrackApp/hsrac.py index cc4265b..e49b520 100644 --- a/EyeTrackApp/hsrac.py +++ b/EyeTrackApp/hsrac.py @@ -257,10 +257,10 @@ class HSRAC_cls(object): if self.blink_detector.response_len() < blink_init_frames: self.blink_detector.add_response(cv2.mean(cropped_image)[0]) - upper_x = center_x + 20 - lower_x = center_x - 20 - upper_y = center_y + 20 - lower_y = center_y - 20 + upper_x = center_x + max(20,radius) + lower_x = center_x - max(20,radius) + upper_y = center_y + max(20,radius) + lower_y = center_y - max(20,radius) self.center_q1.add_response( cv2.mean(safe_crop(gray_frame, lower_x, lower_y, upper_x, upper_y,keepsize=False))[ 0 @@ -330,12 +330,13 @@ class HSRAC_cls(object): # The processing results were the same when I swapped the order of blurring and 1-channelization. frame_gray = cv2.GaussianBlur(frame, (5, 5), 0) hsf_center_x, hsf_center_y = center_x.copy(), center_y.copy() - ransac_xy_offset = (hsf_center_x-20, hsf_center_y-20) - upper_x = hsf_center_x + 20 - lower_x = hsf_center_x - 20 - upper_y = hsf_center_y + 20 - lower_y = hsf_center_y - 20 - + # ransac_xy_offset = (hsf_center_x-20, hsf_center_y-20) + upper_x = hsf_center_x + max(20, radius) + lower_x = hsf_center_x - max(20, radius) + upper_y = hsf_center_y + max(20, radius) + lower_y = hsf_center_y - max(20, radius) + ransac_xy_offset = (lower_x, lower_y) + # Crop the image using the calculated bounds frame_gray_crop = safe_crop(frame_gray, lower_x, lower_y, upper_x, upper_y) @@ -363,7 +364,7 @@ class HSRAC_cls(object): threshold_value = self.center_q1.quartile_1 if threshold_value