From bfb588ef6f528d8b50fd39b5db96744c54497135 Mon Sep 17 00:00:00 2001 From: Prohurtz <48768484+RedHawk989@users.noreply.github.com> Date: Fri, 17 Mar 2023 14:27:44 -0500 Subject: [PATCH] tuning, minor adjustments --- EyeTrackApp/blink.py | 6 +- EyeTrackApp/camera_widget.py | 20 +++---- EyeTrackApp/config.py | 4 +- EyeTrackApp/eye_processor.py | 91 ++++++++++++++++++------------- EyeTrackApp/hsrac.py | 15 +++-- EyeTrackApp/intensity_eye_open.py | 47 ++++++++-------- EyeTrackApp/settings_widget.py | 15 ++++- 7 files changed, 114 insertions(+), 84 deletions(-) diff --git a/EyeTrackApp/blink.py b/EyeTrackApp/blink.py index 75bfcf7..9be8138 100644 --- a/EyeTrackApp/blink.py +++ b/EyeTrackApp/blink.py @@ -14,11 +14,11 @@ def BLINK(self): if len(self.max_ints) > 1: if intensity > min(self.max_ints): - blinkvalue = True + blinkvalue = 0.0 else: - blinkvalue = False + blinkvalue = 0.7 try: return blinkvalue except: - return False + return 0.7 # print(self.blinkvalue, self.max_int, self.min_int, self.frames, intensity) \ No newline at end of file diff --git a/EyeTrackApp/camera_widget.py b/EyeTrackApp/camera_widget.py index 06376c6..806b799 100644 --- a/EyeTrackApp/camera_widget.py +++ b/EyeTrackApp/camera_widget.py @@ -80,13 +80,13 @@ class CameraWidget: [ sg.Text("Mode:", background_color='#424042'), sg.Text("Calibrating", key=self.gui_mode_readout, background_color='#424042'), - sg.Checkbox( - "Circle crop:", - default=self.config.gui_circular_crop, - key=self.gui_circular_crop, - background_color='#424042', - tooltip = "Circle crop only applies to RANSAC3D and Blob.", - ), + # sg.Checkbox( + # "Circle crop:", + # default=self.config.gui_circular_crop, + # key=self.gui_circular_crop, + # background_color='#424042', + # tooltip = "Circle crop only applies to RANSAC3D and Blob.", + # ), ], [sg.Image(filename="", key=self.gui_tracking_image)], [ @@ -201,9 +201,9 @@ class CameraWidget: self.config.rotation_angle = int(values[self.gui_rotation_slider]) changed = True - if self.config.gui_circular_crop != values[self.gui_circular_crop]: - self.config.gui_circular_crop = values[self.gui_circular_crop] - changed = True + # if self.config.gui_circular_crop != values[self.gui_circular_crop]: + # self.config.gui_circular_crop = values[self.gui_circular_crop] + # changed = True if changed: self.main_config.save() diff --git a/EyeTrackApp/config.py b/EyeTrackApp/config.py index f680712..5ab3108 100644 --- a/EyeTrackApp/config.py +++ b/EyeTrackApp/config.py @@ -27,7 +27,7 @@ class EyeTrackSettingsConfig(BaseModel): gui_RANSAC3D: bool = False gui_HSF: bool = False gui_BLOB: bool = False - gui_BLINK: bool = True + gui_BLINK: bool = False gui_HSRAC: bool = True gui_DADDY: bool = False gui_HSF_radius: int = 15 @@ -50,7 +50,7 @@ class EyeTrackSettingsConfig(BaseModel): gui_DADDYP: int = 3 gui_RANSAC3DP: int = 4 gui_BLOBP: int = 5 - + gui_IBO: bool = True gui_skip_autoradius: bool = True gui_thresh_add: int = 20 gui_update_check: bool = True diff --git a/EyeTrackApp/eye_processor.py b/EyeTrackApp/eye_processor.py index bd0e2b9..b4c3fcf 100644 --- a/EyeTrackApp/eye_processor.py +++ b/EyeTrackApp/eye_processor.py @@ -161,6 +161,10 @@ class EyeProcessor: self.skip_blink_detect = False + self.out_y = 0.0 + self.out_x = 0.0 + self.rawx = 0.0 + self.rawy = 0.0 #blink self.max_ints = [] self.max_int = 0 @@ -172,7 +176,7 @@ class EyeProcessor: self.prev_y = None self.daddy = None - + self.current_algo = InformationOrigin.HSRAC try: @@ -247,65 +251,76 @@ class EyeProcessor: except: pass + + def UPDATE(self): + if self.settings.gui_BLINK: + self.eyeopen = BLINK(self) + + if self.settings.gui_IBO: + self.eyeopen = self.ibo.intense(self.rawx, self.rawy, self.current_image) + if self.eyeopen < 0.35: #threshold so the eye fully closes + self.eyeopen = 0.0 + + if self.settings.gui_IBO and self.settings.gui_BLINK: + ibo = self.ibo.intense(self.rawx, self.rawy, self.current_image) + + blink = BLINK(self) + if blink == 0.0: + self.eyeopen = 0.0 + else: + self.eyeopen = ibo + + self.output_images_and_update(self.thresh, EyeInformation(self.current_algo, self.out_x, self.out_y, 0, self.eyeopen)) + + + def BLINKM(self): - x = BLINK(self) + self.eyeopen = BLINK(self) def DADDYM(self): landmark = self.daddy.run(self.current_image_gray) def HSRACM(self): # 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.rawx, self.rawy, self.thresh, gray_frame = self.er_hsrac.run(self.current_image_gray) self.current_image_gray = gray_frame if self.prev_x is None: - self.prev_x = cx - self.prev_y = cy + self.prev_x = self.rawx + self.prev_y = self.rawy #print(self.prev_x, self.prev_y, cx, cy) # #filter values with too much movement # if (cx - self.prev_x) <= 45 and (cy - self.prev_y) <= 45 : # self.prev_x = cx # self.prev_y = cy # self.eyeopen = intense(cx, cy, uncropframe, self.eye_id) - self.eyeopen = self.ibo.intense(cx,cy,uncropframe) - out_x, out_y = cal_osc(self, cx, cy) + # self.eyeopen = self.ibo.intense(cx,cy,uncropframe) + self.out_x, self.out_y = cal_osc(self, self.rawx, self.rawy) #print(self.eyeoffx, self.eyeopen) - - if self.eyeoffx: - self.output_images_and_update(thresh, EyeInformation(InformationOrigin.HSRAC, out_x, out_y, 0, self.eyeopen)) #update app - else: - self.output_images_and_update(thresh, EyeInformation(InformationOrigin.HSRAC, out_x, out_y, 0, self.eyeopen)) + self.current_algorithm = InformationOrigin.HSRAC + # else: # print("EYE MOVED TOO FAST") # self.output_images_and_update(thresh, EyeInformation(InformationOrigin.HSRAC, 0, 0, 0, False)) def HSFM(self): # todo: added process to initialise er_hsf when resolution changes - cx, cy, frame = self.er_hsf.run(self.current_image_gray) - self.eyeopen = self.ibo.intense(cx, cy, self.current_image_gray) - out_x, out_y = cal_osc(self, cx, cy) - if cx == 0: - self.output_images_and_update(frame, EyeInformation(InformationOrigin.HSF, out_x, out_y, 0, self.eyeopen)) #update app - else: - self.output_images_and_update(frame, EyeInformation(InformationOrigin.HSF, out_x, out_y, 0, self.eyeopen)) - + self.rawx, self.rawy, self.thresh = self.er_hsf.run(self.current_image_gray) + self.eyeopen = self.ibo.intense(self.rawx, self.rawy, self.current_image_gray) + out_x, out_y = cal_osc(self, self.rawx, self.rawy) + self.current_algorithm = InformationOrigin.HSF + def RANSAC3DM(self): - cx, cy, thresh = RANSAC3D(self) - self.eyeopen = self.ibo.intense(cx, cy, self.current_image_gray) - out_x, out_y = cal_osc(self, cx, cy) - if cx == 0: - self.output_images_and_update(thresh, EyeInformation(InformationOrigin.RANSAC, out_x, out_y, 0, self.eyeopen)) #update app - else: - self.output_images_and_update(thresh, EyeInformation(InformationOrigin.RANSAC, out_x, out_y, 0, self.eyeopen)) - + self.rawx, self.rawy, self.thresh = RANSAC3D(self) + self.eyeopen = self.ibo.intense(self.rawx, self.rawy, self.current_image_gray) + out_x, out_y = cal_osc(self, self.rawx, self.rawy) + self.current_algorithm = InformationOrigin.RANSAC + def BLOBM(self): - cx, cy, thresh = BLOB(self) - self.eyeopen = self.ibo.intense(cx, cy, self.current_image_gray) - out_x, out_y = cal_osc(self, cx, cy) - if cx == 0: - self.output_images_and_update(thresh, EyeInformation(InformationOrigin.HSRAC, out_x, out_y, 0, self.eyeopen)) #update app - else: - self.output_images_and_update(thresh, EyeInformation(InformationOrigin.HSRAC, out_x, out_y, 0, self.eyeopen)) - + self.rawx, self.rawy, self.thresh = BLOB(self) + self.eyeopen = self.ibo.intense(self.rawx, self.rawy, self.current_image_gray) + out_x, out_y = cal_osc(self, self.rawx, self.rawy) + self.current_algorithm = InformationOrigin.BLOB + def ALGOSELECT(self): @@ -492,7 +507,9 @@ class EyeProcessor: #self.output_images_and_update(frame, EyeInformation(InformationOrigin.HSF, out_x, out_y, 0, False)) #update app self.ALGOSELECT() #run our algos in priority order set in settings - self.BLINKM() + self.UPDATE() + + diff --git a/EyeTrackApp/hsrac.py b/EyeTrackApp/hsrac.py index 97f34fb..8cf1bfa 100644 --- a/EyeTrackApp/hsrac.py +++ b/EyeTrackApp/hsrac.py @@ -386,8 +386,7 @@ class HSRAC_cls(object): # threshold_value = min_val + thresh_add if not blink_bd and self.blink_detector.enable_detect_flg: - print(min_val, thresh_add, self.center_q1.quartile_1) - cv2.threshold(frame_gray_crop, ((min_val + self.center_q1.quartile_1) - 10) / 2, 255, cv2.THRESH_BINARY_INV, dst=th_frame) + cv2.threshold(frame_gray_crop, ((min_val + self.center_q1.quartile_1) - thresh_add) / 2, 255, cv2.THRESH_BINARY_INV, dst=th_frame) cv2.morphologyEx(th_frame, cv2.MORPH_OPEN, self.kernel, dst=fic_frame) # cv2.morphologyEx(fic_frame, cv2.MORPH_CLOSE, self.kernel, dst=fic_frame) # cv2.erode(fic_frame,self.kernel,dst=fic_frame) @@ -422,7 +421,7 @@ class HSRAC_cls(object): if not contours: # If empty, go to next loop - return int(center_x), int(center_y), th_frame, frame, gray_frame + return int(center_x), int(center_y), th_frame, frame cnt_ind = None max_area = -1 for i, cnt in enumerate(contours): @@ -439,7 +438,7 @@ class HSRAC_cls(object): # ransac_data is None==maxcnt.shape[0]= frame.shape[1]: # TODO: these checks should be able to be removed, cause seems to be fixed. - int_x = frame.shape[1] - 1 - obb = True - print('CAUGHT X OUT OF BOUNDS') + + # if int_x >= frame.shape[1]: + # int_x = frame.shape[1] - 1 + # obb = True + # print('CAUGHT X OUT OF BOUNDS') - if int_x < 0: - int_x = True - print('CAUGHT X UNDER BOUNDS') + #if int_x < 0: + # int_x = True + # print('CAUGHT X UNDER BOUNDS') - if int_y >= frame.shape[0]: - int_y = frame.shape[0] - 1 - oob = True - print('CAUGHT Y OUT OF BOUNDS') + # if int_y >= frame.shape[0]: + # int_y = frame.shape[0] - 1 + # oob = True + # print('CAUGHT Y OUT OF BOUNDS') - if int_y < 0: - int_y = 1 - oob = True - print('CAUGHT Y UNDER BOUNDS') + # if int_y < 0: + # int_y = 1 + # oob = True + # print('CAUGHT Y UNDER BOUNDS') if oob != True: data_val = self.data[int_y, int_x] @@ -198,26 +199,26 @@ class IntensityBasedOpeness: changed = True # print("var adjusted") else: - intensitya = max(data_val - 3, 1) # if current intensity value is less (more pupil), save that + intensitya = max(data_val - 5, 1) # if current intensity value is less (more pupil), save that self.data[int_y, int_x] = intensitya # set value changed = True # min pupil global if self.maxval == 0: # that value is not yet saved self.maxval = intensity # set value at 0 index - # print("create max", intensity) + # print("create max", intensity) else: 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 - # print("new max", intensity) + # print("new max", intensity) else: intensityd = max(self.maxval - 10, 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 if newval_flg: # Do the same thing as in the original version. - print('[INFO] Something went wrong, assuming blink.') - eyeopen = 0.7 + print('[INFO] [IBO] Something went wrong') + eyeopen = 0.9 else: maxp = self.data[int_y, int_x] minp = self.maxval @@ -226,7 +227,7 @@ class IntensityBasedOpeness: eyeopen = 1 - eyeopen # eyeopen = eyeopen - 0.2 # print(intensity, maxp, minp, x, y) - print(f"EYEOPEN: {eyeopen}") + # print(f"EYEOPEN: {eyeopen}") # print(int(x), int(y), eyeopen, maxp, minp) # print(self.data[0, -1]) # print(self.maxval) diff --git a/EyeTrackApp/settings_widget.py b/EyeTrackApp/settings_widget.py index ba7e501..0fc10c6 100644 --- a/EyeTrackApp/settings_widget.py +++ b/EyeTrackApp/settings_widget.py @@ -26,6 +26,7 @@ class SettingsWidget: self.gui_DADDYP = f"-DADDYP{widget_id}-" self.gui_RANSAC3D = f"-RANSAC3D{widget_id}-" self.gui_BLINK = f"-BLINK{widget_id}-" + self.gui_IBO = f"-THRESHADD{widget_id}-" self.gui_HSRAC = f"-HSRAC{widget_id}-" self.gui_HSF_radius = f"-HSFRADIUS{widget_id}-" self.gui_blob_maxsize = f"-BLOBMAXSIZE{widget_id}-" @@ -200,7 +201,15 @@ class SettingsWidget: ], [ sg.Checkbox( - "Blink Algo", + "Intensity Based Openness", + default=self.config.gui_IBO, + key=self.gui_IBO, + background_color='#424042', + ), + ], + [ + sg.Checkbox( + "Bianary Blink Algo", default=self.config.gui_BLINK, key=self.gui_BLINK, background_color='#424042', @@ -465,6 +474,10 @@ class SettingsWidget: if self.config.gui_BLINK != values[self.gui_BLINK]: self.config.gui_BLINK = values[self.gui_BLINK] changed = True + + if self.config.gui_IBO != values[self.gui_IBO]: + self.config.gui_IBO = values[self.gui_IBO] + changed = True if self.config.gui_HSF_radius != values[self.gui_HSF_radius]: self.config.gui_HSF_radius = values[self.gui_HSF_radius]