tuning, minor adjustments

This commit is contained in:
Prohurtz 2023-03-17 14:27:44 -05:00
parent 4b361a74db
commit bfb588ef6f
7 changed files with 114 additions and 84 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -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]<sample_num
# go to next loop
# pass
return int(center_x), int(center_y), th_frame, frame, gray_frame
return int(center_x), int(center_y), th_frame, frame
# crop_start_time = timeit.default_timer()
cx, cy, w, h, theta = ransac_data
@ -490,9 +489,9 @@ class HSRAC_cls(object):
# self.timedict["total_cv"].append(cv_end_time - cv_start_time)
try:
return int(cx), int(cy), th_frame, frame, gray_frame
return int(cx), int(cy), th_frame, frame
except:
return int(center_x), int(center_y), th_frame, frame, gray_frame
return int(center_x), int(center_y), th_frame, frame
@ -512,8 +511,8 @@ class External_Run_HSRACS(object):
#debug code
# center_x, center_y,cropbox,ori_frame, thresh, frame, gray_frame = self.algo.single_run()
# return center_x, center_y,cropbox,ori_frame, thresh, frame, gray_frame
center_x, center_y, thresh, frame, gray_frame = self.algo.single_run()
return center_x, center_y, thresh, frame, gray_frame
center_x, center_y, thresh, frame = self.algo.single_run()
return center_x, center_y, thresh, frame

View File

@ -144,7 +144,7 @@ class IntensityBasedOpeness:
def intense(self, x, y, frame):
self.check(frame.shape)
int_x, int_y = int(x), int(y)
print(int_x, int_y, frame.shape[1], frame.shape[0] )
upper_x = min(int_x + 25, frame.shape[1]) #TODO make this a setting
lower_x = max(int_x - 25, 0)
upper_y = min(int_y + 25, frame.shape[0])
@ -152,7 +152,7 @@ class IntensityBasedOpeness:
frame_crop = frame[lower_y:upper_y, lower_x:upper_x]
# frame_crop = frame
# cv2.imwrite("frame.jpg", frame_crop)
# The same can be done with cv2.integral, but since there is only one area of the rectangle for which we want to know the total value, there is no advantage in terms of computational complexity.
intensity = frame_crop.sum() + 1
# numpy:np.sum(),ndarray.sum()
@ -163,24 +163,25 @@ class IntensityBasedOpeness:
newval_flg = False
oob = False
if int_x >= 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)

View File

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