From 8d29d24127d92cd704b4af20c29a1f728476bf5d Mon Sep 17 00:00:00 2001 From: Prohurtz <48768484+RedHawk989@users.noreply.github.com> Date: Thu, 11 May 2023 08:58:07 -0700 Subject: [PATCH] complete implimentation of per eye cirlcle crop in ransac --- EyeTrackApp/eye_processor.py | 38 ++----------------------- EyeTrackApp/ransac.py | 55 +++++++++++++++++++++--------------- 2 files changed, 35 insertions(+), 58 deletions(-) diff --git a/EyeTrackApp/eye_processor.py b/EyeTrackApp/eye_processor.py index ec2f51c..939639a 100644 --- a/EyeTrackApp/eye_processor.py +++ b/EyeTrackApp/eye_processor.py @@ -136,7 +136,6 @@ class EyeProcessor: self.er_hsf = None self.er_hsrac = None self.er_daddy = None - self.ibo = IntensityBasedOpeness(eyeside=EyeLR.LEFT if self.eye_id is EyeId.LEFT else EyeLR.RIGHT if eye_id is EyeId.RIGHT else -1) self.roi_include_set = {"rotation_angle", "roi_window_x", "roi_window_y"} @@ -391,13 +390,6 @@ class EyeProcessor: print("\033[94m[INFO] Exiting Tracking thread\033[0m") return - #try: - # (self.eye_id, eye_info) = self.msg_queue.get(block=True, timeout=0.1) - # print(self.eye_id) - #except: - #print('eeeeeeee') - #pass - if self.config.roi_window_w <= 0 or self.config.roi_window_h <= 0: # At this point, we're waiting for the user to set up the ROI window in the GUI. @@ -406,8 +398,7 @@ class EyeProcessor: return continue - - + # If our ROI configuration has changed, reset our model and detector if (self.camera_model is None or self.detector_3d is None @@ -445,32 +436,7 @@ class EyeProcessor: self.current_image, cv2.COLOR_BGR2GRAY ) self.current_image_gray_clean = self.current_image_gray.copy() #copy this frame to have a clean image for blink algo - # print(self.settings.gui_RANSAC3D) - - # BLINK(self) - - # cx, cy, thresh = HSRAC(self) - # out_x, out_y = cal_osc(self, cx, cy) - # if cx == 0: - # self.output_images_and_update(thresh, EyeInfo(EyeInfoOrigin.HSRAC, out_x, out_y, 0, True)) #update app - # else: - # self.output_images_and_update(thresh, EyeInfo(EyeInfoOrigin.HSRAC, out_x, out_y, 0, self.blinkvalue)) - - - # cx, cy, thresh = RANSAC3D(self) - # out_x, out_y = cal_osc(self, cx, cy) - # self.output_images_and_update(thresh, EyeInfo(EyeInfoOrigin.RANSAC, out_x, out_y, 0, False)) #update app - - - # cx, cy, larger_threshold = BLOB(self) - # out_x, out_y = cal_osc(self, cx, cy) - # self.output_images_and_update(larger_threshold, EyeInfo(EyeInfoOrigin.BLOB, out_x, out_y, 0, False)) #update app - - #center_x, center_y, frame = HSF(self) #run algo - #out_x, out_y = cal_osc(self, center_x, center_y) #filter and calibrate - #self.output_images_and_update(frame, EyeInfo(EyeInfoOrigin.HSF, out_x, out_y, 0, False)) #update app - + self.ALGOSELECT() #run our algos in priority order set in settings - #self.BLOBM() self.UPDATE() diff --git a/EyeTrackApp/ransac.py b/EyeTrackApp/ransac.py index d50766d..9bfb257 100644 --- a/EyeTrackApp/ransac.py +++ b/EyeTrackApp/ransac.py @@ -27,6 +27,8 @@ Copyright (c) 2023 EyeTrackVR <3 ''' import cv2 import numpy as np +from enums import EyeLR + def ellipse_model(data, y, f): """ @@ -134,6 +136,31 @@ def fit_rotated_ellipse(data, P): return (cx, cy, w, h, theta) +def circle_crop(self): + if self.cct == 0: + try: + ht, wd = self.current_image_gray.shape[:2] + radius = int(float(self.lkg_projected_sphere["axes"][0])) + self.xc = int(float(self.lkg_projected_sphere["center"][0])) + self.yc = int(float(self.lkg_projected_sphere["center"][1])) + if radius < 8: #minimum size TODO: make shure this size is enough + radius = 8 + # draw filled circle in white on black background as mask + mask = np.zeros((ht, wd), dtype=np.uint8) + mask = cv2.circle(mask, (self.xc, self.yc), radius, 255, -1) + # create white colored background + color = np.full_like(self.current_image_gray, (255)) + # apply mask to image + masked_img = cv2.bitwise_and(self.current_image_gray, self.current_image_gray, mask=mask) + # apply inverse mask to colored image + masked_color = cv2.bitwise_and(color, color, mask=255 - mask) + # combine the two masked images + self.current_image_gray = cv2.add(masked_img, masked_color) + except: + pass + else: + self.cct = self.cct - 1 + def RANSAC3D(self): f = False kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3, 3)) @@ -149,31 +176,15 @@ def RANSAC3D(self): # crop the image earlier; it gives us less possible dark area to get confused about in the # next step. - if self.config.gui_circular_crop == True: - if self.cct == 0: - try: - ht, wd = self.current_image_gray.shape[:2] - radius = int(float(self.lkg_projected_sphere["axes"][0])) - self.xc = int(float(self.lkg_projected_sphere["center"][0])) - self.yc = int(float(self.lkg_projected_sphere["center"][1])) - # draw filled circle in white on black background as mask - mask = np.zeros((ht, wd), dtype=np.uint8) - mask = cv2.circle(mask, (self.xc, self.yc), radius, 255, -1) - # create white colored background - color = np.full_like(self.current_image_gray, (255)) - # apply mask to image - masked_img = cv2.bitwise_and(self.current_image_gray, self.current_image_gray, mask=mask) - # apply inverse mask to colored image - masked_color = cv2.bitwise_and(color, color, mask=255 - mask) - # combine the two masked images - self.current_image_gray = cv2.add(masked_img, masked_color) - except: - pass - else: - self.cct = self.cct - 1 + if self.eye_id == EyeId.LEFT and self.config.gui_circular_crop_left == True: #TODO TEST function + circle_crop(self) else: self.cct = 300 + if self.eye_id == EyeId.RIGHT and self.config.gui_circular_crop_right == True: + circle_crop(self) + else: + self.cct = 300 # Crop first to reduce the amount of data to process. newFrame2 = self.current_image_gray.copy()