Merge pull request #67 from PallasNeko/fix/autoradius

Fix autoradius and skip_autoradius
This commit is contained in:
Prohurtz 2023-02-10 16:07:24 -06:00 committed by GitHub
commit 5428ef6d53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 75 additions and 40 deletions

View File

@ -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

View File

@ -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):

View File

@ -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<min_val + thresh_add:
# In most of these cases, the pupil is at the edge of the eye.
frame_gray_crop=cv2.threshold(frame_gray_crop,(min_val + thresh_add*4+threshold_value)/2, 255, cv2.THRESH_BINARY)[1]
thresh = cv2.threshold(frame_gray_crop, (min_val + thresh_add*4+threshold_value)/2, 255, cv2.THRESH_BINARY)[1]
else:
threshold_value = self.center_q1.quartile_1
@ -458,7 +459,7 @@ class HSRAC_cls(object):
# print()
# return center_x, center_y,cropbox, ori_frame,thresh, frame, gray_frame
# print(frame_gray.shape, thresh.shape)
try:
return int(cx), int(cy), thresh, frame, gray_frame
except:
@ -468,7 +469,13 @@ class HSRAC_cls(object):
class External_Run_HSRACS(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 = HSRAC_cls()
def run(self, current_image_gray):