mirror of
https://github.com/EyeTrackVR/EyeTrackVR.git
synced 2025-11-04 14:39:42 +08:00
Merge pull request #67 from PallasNeko/fix/autoradius
Fix autoradius and skip_autoradius
This commit is contained in:
commit
5428ef6d53
@ -150,8 +150,8 @@ class EyeProcessor:
|
|||||||
self.camera_model = None
|
self.camera_model = None
|
||||||
self.detector_3d = None
|
self.detector_3d = None
|
||||||
|
|
||||||
self.camera_model = None
|
self.er_hsf = None
|
||||||
self.detector_3d = None
|
self.er_hsrac = None
|
||||||
|
|
||||||
self.failed = 0
|
self.failed = 0
|
||||||
|
|
||||||
@ -234,7 +234,7 @@ class EyeProcessor:
|
|||||||
rotation_matrix,
|
rotation_matrix,
|
||||||
(cols, rows),
|
(cols, rows),
|
||||||
borderMode=cv2.BORDER_CONSTANT,
|
borderMode=cv2.BORDER_CONSTANT,
|
||||||
borderValue=(255, 255, 255),
|
borderValue=(64, 64, 64),#(255, 255, 255),
|
||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
except:
|
except:
|
||||||
@ -245,7 +245,8 @@ class EyeProcessor:
|
|||||||
|
|
||||||
|
|
||||||
def HSRACM(self):
|
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
|
self.current_image_gray = gray_frame
|
||||||
if self.prev_x is None:
|
if self.prev_x is None:
|
||||||
self.prev_x = cx
|
self.prev_x = cx
|
||||||
@ -267,7 +268,8 @@ class EyeProcessor:
|
|||||||
# print("EYE MOVED TOO FAST")
|
# print("EYE MOVED TOO FAST")
|
||||||
# self.output_images_and_update(thresh, EyeInformation(InformationOrigin.HSRAC, 0, 0, 0, False))
|
# self.output_images_and_update(thresh, EyeInformation(InformationOrigin.HSRAC, 0, 0, 0, False))
|
||||||
def HSFM(self):
|
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)
|
self.eyeopen = intense(cx, cy, self.current_image_gray)
|
||||||
out_x, out_y = cal_osc(self, cx, cy)
|
out_x, out_y = cal_osc(self, cx, cy)
|
||||||
if cx == 0:
|
if cx == 0:
|
||||||
@ -326,16 +328,36 @@ class EyeProcessor:
|
|||||||
self.secondalgo = None
|
self.secondalgo = None
|
||||||
self.thirdalgo = None
|
self.thirdalgo = None
|
||||||
self.fourthalgo = None
|
self.fourthalgo = None
|
||||||
|
algolist = [None, None, None, None, None]
|
||||||
|
|
||||||
#set algo priorities
|
#set algo priorities
|
||||||
|
|
||||||
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
|
if self.settings.gui_HSF:
|
||||||
self.firstalgo = self.HSFM
|
if self.er_hsf is None:
|
||||||
elif self.settings.gui_HSF and self.settings.gui_HSFP == 2:
|
self.er_hsf = External_Run_HSF(self.settings.gui_skip_autoradius, self.settings.gui_HSF_radius)
|
||||||
self.secondalgo = self.HSFM
|
algolist[self.settings.gui_HSFP] = self.HSFM
|
||||||
elif self.settings.gui_HSF and self.settings.gui_HSFP == 3:
|
else:
|
||||||
self.thirdalgo = self.HSFM
|
if self.er_hsf is not None:
|
||||||
elif self.settings.gui_HSF and self.settings.gui_HSFP == 4:
|
self.er_hsf = None
|
||||||
self.fourthalgo = self.HSFM
|
|
||||||
|
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
|
||||||
|
|
||||||
|
_, 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:
|
if self.settings.gui_RANSAC3D and self.settings.gui_RANSAC3DP == 1:
|
||||||
self.firstalgo = self.RANSAC3DM
|
self.firstalgo = self.RANSAC3DM
|
||||||
@ -346,14 +368,14 @@ class EyeProcessor:
|
|||||||
elif self.settings.gui_RANSAC3D and self.settings.gui_RANSAC3DP == 4:
|
elif self.settings.gui_RANSAC3D and self.settings.gui_RANSAC3DP == 4:
|
||||||
self.fourthalgo = self.RANSAC3DM
|
self.fourthalgo = self.RANSAC3DM
|
||||||
|
|
||||||
if self.settings.gui_HSRAC and self.settings.gui_HSRACP == 1:
|
# if self.settings.gui_HSRAC and self.settings.gui_HSRACP == 1:
|
||||||
self.firstalgo = self.HSRACM
|
# self.firstalgo = self.HSRACM
|
||||||
elif self.settings.gui_HSRAC and self.settings.gui_HSRACP == 2:
|
# elif self.settings.gui_HSRAC and self.settings.gui_HSRACP == 2:
|
||||||
self.secondalgo = self.HSRACM
|
# self.secondalgo = self.HSRACM
|
||||||
elif self.settings.gui_HSRAC and self.settings.gui_HSRACP == 3:
|
# elif self.settings.gui_HSRAC and self.settings.gui_HSRACP == 3:
|
||||||
self.thirdalgo = self.HSRACM
|
# self.thirdalgo = self.HSRACM
|
||||||
elif self.settings.gui_HSRAC and self.settings.gui_HSRACP == 4:
|
# elif self.settings.gui_HSRAC and self.settings.gui_HSRACP == 4:
|
||||||
self.fourthalgo = self.HSRACM
|
# self.fourthalgo = self.HSRACM
|
||||||
|
|
||||||
if self.settings.gui_BLOB and self.settings.gui_BLOBP == 1:
|
if self.settings.gui_BLOB and self.settings.gui_BLOBP == 1:
|
||||||
self.firstalgo = self.BLOBM
|
self.firstalgo = self.BLOBM
|
||||||
|
|||||||
@ -602,10 +602,10 @@ class HSF_cls(object):
|
|||||||
if self.blink_detector.response_len() < blink_init_frames:
|
if self.blink_detector.response_len() < blink_init_frames:
|
||||||
self.blink_detector.add_response(cv2.mean(cropped_image)[0])
|
self.blink_detector.add_response(cv2.mean(cropped_image)[0])
|
||||||
|
|
||||||
upper_x = center_x + self.center_correct.center_q1_radius
|
upper_x = center_x + max(20, radius)#self.center_correct.center_q1_radius
|
||||||
lower_x = center_x - self.center_correct.center_q1_radius
|
lower_x = center_x - max(20, radius)#self.center_correct.center_q1_radius
|
||||||
upper_y = center_y + self.center_correct.center_q1_radius
|
upper_y = center_y + max(20, radius)#self.center_correct.center_q1_radius
|
||||||
lower_y = center_y - self.center_correct.center_q1_radius
|
lower_y = center_y - max(20, radius)#self.center_correct.center_q1_radius
|
||||||
|
|
||||||
self.center_q1.add_response(
|
self.center_q1.add_response(
|
||||||
cv2.mean(safe_crop(gray_frame, lower_x, lower_y, upper_x, upper_y,keepsize=False))[
|
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
|
return center_x, center_y, frame
|
||||||
|
|
||||||
class External_Run_HSF(object):
|
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()
|
self.algo = HSF_cls()
|
||||||
|
|
||||||
def run(self, current_image_gray):
|
def run(self, current_image_gray):
|
||||||
|
|||||||
@ -257,10 +257,10 @@ class HSRAC_cls(object):
|
|||||||
if self.blink_detector.response_len() < blink_init_frames:
|
if self.blink_detector.response_len() < blink_init_frames:
|
||||||
self.blink_detector.add_response(cv2.mean(cropped_image)[0])
|
self.blink_detector.add_response(cv2.mean(cropped_image)[0])
|
||||||
|
|
||||||
upper_x = center_x + 20
|
upper_x = center_x + max(20,radius)
|
||||||
lower_x = center_x - 20
|
lower_x = center_x - max(20,radius)
|
||||||
upper_y = center_y + 20
|
upper_y = center_y + max(20,radius)
|
||||||
lower_y = center_y - 20
|
lower_y = center_y - max(20,radius)
|
||||||
self.center_q1.add_response(
|
self.center_q1.add_response(
|
||||||
cv2.mean(safe_crop(gray_frame, lower_x, lower_y, upper_x, upper_y,keepsize=False))[
|
cv2.mean(safe_crop(gray_frame, lower_x, lower_y, upper_x, upper_y,keepsize=False))[
|
||||||
0
|
0
|
||||||
@ -330,11 +330,12 @@ class HSRAC_cls(object):
|
|||||||
# The processing results were the same when I swapped the order of blurring and 1-channelization.
|
# The processing results were the same when I swapped the order of blurring and 1-channelization.
|
||||||
frame_gray = cv2.GaussianBlur(frame, (5, 5), 0)
|
frame_gray = cv2.GaussianBlur(frame, (5, 5), 0)
|
||||||
hsf_center_x, hsf_center_y = center_x.copy(), center_y.copy()
|
hsf_center_x, hsf_center_y = center_x.copy(), center_y.copy()
|
||||||
ransac_xy_offset = (hsf_center_x-20, hsf_center_y-20)
|
# ransac_xy_offset = (hsf_center_x-20, hsf_center_y-20)
|
||||||
upper_x = hsf_center_x + 20
|
upper_x = hsf_center_x + max(20, radius)
|
||||||
lower_x = hsf_center_x - 20
|
lower_x = hsf_center_x - max(20, radius)
|
||||||
upper_y = hsf_center_y + 20
|
upper_y = hsf_center_y + max(20, radius)
|
||||||
lower_y = hsf_center_y - 20
|
lower_y = hsf_center_y - max(20, radius)
|
||||||
|
ransac_xy_offset = (lower_x, lower_y)
|
||||||
|
|
||||||
# Crop the image using the calculated bounds
|
# Crop the image using the calculated bounds
|
||||||
|
|
||||||
@ -363,7 +364,7 @@ class HSRAC_cls(object):
|
|||||||
threshold_value = self.center_q1.quartile_1
|
threshold_value = self.center_q1.quartile_1
|
||||||
if threshold_value<min_val + thresh_add:
|
if threshold_value<min_val + thresh_add:
|
||||||
# In most of these cases, the pupil is at the edge of the eye.
|
# 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:
|
else:
|
||||||
threshold_value = self.center_q1.quartile_1
|
threshold_value = self.center_q1.quartile_1
|
||||||
@ -468,7 +469,13 @@ class HSRAC_cls(object):
|
|||||||
|
|
||||||
|
|
||||||
class External_Run_HSRACS(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()
|
self.algo = HSRAC_cls()
|
||||||
|
|
||||||
def run(self, current_image_gray):
|
def run(self, current_image_gray):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user