mirror of
https://github.com/EyeTrackVR/EyeTrackVR.git
synced 2025-11-04 14:39:42 +08:00
end of day update
This commit is contained in:
parent
df8efd55d1
commit
77b2389a03
20
EyeTrackApp/blink.py
Normal file
20
EyeTrackApp/blink.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import numpy as np
|
||||||
|
|
||||||
|
def BLINK(self):
|
||||||
|
|
||||||
|
intensity = np.sum(self.current_image_gray_clean)
|
||||||
|
self.frames = self.frames + 1
|
||||||
|
|
||||||
|
if intensity > self.max_int:
|
||||||
|
self.max_int = intensity
|
||||||
|
if self.frames > 200:
|
||||||
|
self.max_ints.append(self.max_int)
|
||||||
|
if intensity < self.min_int:
|
||||||
|
self.min_int = intensity
|
||||||
|
|
||||||
|
if len(self.max_ints) > 1:
|
||||||
|
if intensity > min(self.max_ints):
|
||||||
|
self.blinkvalue = True
|
||||||
|
else:
|
||||||
|
self.blinkvalue = False
|
||||||
|
# print(self.blinkvalue, self.max_int, self.min_int, self.frames, intensity)
|
||||||
@ -55,6 +55,7 @@ from haar_surround_feature import *
|
|||||||
from blob import *
|
from blob import *
|
||||||
from ransac import *
|
from ransac import *
|
||||||
from hsrac import *
|
from hsrac import *
|
||||||
|
from blink import *
|
||||||
|
|
||||||
class InformationOrigin(Enum):
|
class InformationOrigin(Enum):
|
||||||
RANSAC = 1
|
RANSAC = 1
|
||||||
@ -397,40 +398,6 @@ class EyeProcessor:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def BLINK(self):
|
|
||||||
|
|
||||||
intensity = np.sum(self.current_image_gray)
|
|
||||||
self.frames = self.frames + 1
|
|
||||||
|
|
||||||
if intensity > self.max_int:
|
|
||||||
self.max_int = intensity
|
|
||||||
if self.frames > 200:
|
|
||||||
self.max_ints.append(self.max_int)
|
|
||||||
if intensity < self.min_int:
|
|
||||||
self.min_int = intensity
|
|
||||||
|
|
||||||
if len(self.max_ints) > 1:
|
|
||||||
if intensity > min(self.max_ints):
|
|
||||||
print("Blink")
|
|
||||||
self.blinkvalue = True
|
|
||||||
else:
|
|
||||||
self.blinkvalue = False
|
|
||||||
print(self.blinkvalue)
|
|
||||||
|
|
||||||
|
|
||||||
def ALGOSELECT(self):
|
def ALGOSELECT(self):
|
||||||
|
|
||||||
if self.failed == 0 and self.firstalgo != None:
|
if self.failed == 0 and self.firstalgo != None:
|
||||||
@ -569,11 +536,16 @@ class EyeProcessor:
|
|||||||
self.current_image_gray_clean = self.current_image_gray.copy() #copy this frame to have a clean image for blink algo
|
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)
|
# print(self.settings.gui_RANSAC3D)
|
||||||
|
|
||||||
|
BLINK(self)
|
||||||
|
|
||||||
cx, cy, thresh = HSRAC(self)
|
cx, cy, thresh = HSRAC(self)
|
||||||
out_x, out_y = cal_osc(self, cx, cy)
|
out_x, out_y = cal_osc(self, cx, cy)
|
||||||
self.output_images_and_update(thresh, EyeInformation(InformationOrigin.HSRAC, out_x, out_y, 0, False)) #update app
|
if cx == 0:
|
||||||
|
self.output_images_and_update(thresh, EyeInformation(InformationOrigin.HSRAC, out_x, out_y, 0, True)) #update app
|
||||||
|
else:
|
||||||
|
self.output_images_and_update(thresh, EyeInformation(InformationOrigin.HSRAC, out_x, out_y, 0, self.blinkvalue))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# cx, cy, thresh = RANSAC3D(self)
|
# cx, cy, thresh = RANSAC3D(self)
|
||||||
# out_x, out_y = cal_osc(self, cx, cy)
|
# out_x, out_y = cal_osc(self, cx, cy)
|
||||||
# self.output_images_and_update(thresh, EyeInformation(InformationOrigin.RANSAC, out_x, out_y, 0, False)) #update app
|
# self.output_images_and_update(thresh, EyeInformation(InformationOrigin.RANSAC, out_x, out_y, 0, False)) #update app
|
||||||
|
|||||||
@ -13,7 +13,8 @@ import math
|
|||||||
lru_maxsize_vvs = 16
|
lru_maxsize_vvs = 16
|
||||||
lru_maxsize_vs = 64
|
lru_maxsize_vs = 64
|
||||||
# CV param
|
# CV param
|
||||||
default_radius = 20
|
|
||||||
|
default_radius = 15
|
||||||
auto_radius_range = (default_radius - 10, default_radius + 10) # (10,30)
|
auto_radius_range = (default_radius - 10, default_radius + 10) # (10,30)
|
||||||
blink_init_frames = 60 * 3 # 60fps*3sec,Number of blink statistical frames
|
blink_init_frames = 60 * 3 # 60fps*3sec,Number of blink statistical frames
|
||||||
# step==(x,y)
|
# step==(x,y)
|
||||||
@ -523,6 +524,8 @@ def fit_rotated_ellipse(data, P):
|
|||||||
|
|
||||||
def HSRAC(self):
|
def HSRAC(self):
|
||||||
|
|
||||||
|
default_radius = self.settings.gui_HSF_radius
|
||||||
|
auto_radius_range = (default_radius - 10, default_radius + 10) # (10,30)
|
||||||
frame = self.current_image_gray
|
frame = self.current_image_gray
|
||||||
if self.now_mode == self.cv_mode[1]:
|
if self.now_mode == self.cv_mode[1]:
|
||||||
|
|
||||||
@ -530,27 +533,27 @@ def HSRAC(self):
|
|||||||
prev_res_len = len(self.response_list)
|
prev_res_len = len(self.response_list)
|
||||||
# adjustment of radius
|
# adjustment of radius
|
||||||
if prev_res_len == 1:
|
if prev_res_len == 1:
|
||||||
# len==1==self.response_list==[self.default_radius]
|
# len==1==self.response_list==[default_radius]
|
||||||
self.cvparam.radius = self.auto_radius_range[0]
|
self.cvparam.radius = self.auto_radius_range[0]
|
||||||
elif prev_res_len == 2:
|
elif prev_res_len == 2:
|
||||||
# len==2==self.response_list==[self.default_radius, self.auto_radius_range[0]]
|
# len==2==self.response_list==[default_radius, self.auto_radius_range[0]]
|
||||||
self.cvparam.radius = self.auto_radius_range[1]
|
self.cvparam.radius = self.auto_radius_range[1]
|
||||||
elif prev_res_len == 3:
|
elif prev_res_len == 3:
|
||||||
# len==3==self.response_list==[self.default_radius,self.auto_radius_range[0],self.auto_radius_range[1]]
|
# len==3==self.response_list==[default_radius,self.auto_radius_range[0],self.auto_radius_range[1]]
|
||||||
sort_res = sorted(self.response_list, key=lambda x: x[1])[0]
|
sort_res = sorted(self.response_list, key=lambda x: x[1])[0]
|
||||||
# Extract the radius with the lowest response value
|
# Extract the radius with the lowest response value
|
||||||
if sort_res[0] == self.default_radius:
|
if sort_res[0] == default_radius:
|
||||||
# If the default value is best, change self.now_mode to init after setting radius to the default value.
|
# If the default value is best, change self.now_mode to init after setting radius to the default value.
|
||||||
self.cvparam.radius = self.default_radius
|
self.cvparam.radius = default_radius
|
||||||
self.now_mode = self.cv_mode[2] if not self.skip_blink_detect else self.cv_mode[3]
|
self.now_mode = self.cv_mode[2] if not self.skip_blink_detect else self.cv_mode[3]
|
||||||
self.response_list = []
|
self.response_list = []
|
||||||
elif sort_res[0] == self.auto_radius_range[0]:
|
elif sort_res[0] == self.auto_radius_range[0]:
|
||||||
self.radius_cand_list = [i for i in range(self.auto_radius_range[0], self.default_radius, self.default_step[0])][1:]
|
self.radius_cand_list = [i for i in range(self.auto_radius_range[0], default_radius, self.default_step[0])][1:]
|
||||||
# self.default_step is defined separately for xy, but radius is shared by xy, so it may be buggy
|
# self.default_step is defined separately for xy, but radius is shared by xy, so it may be buggy
|
||||||
# It should be no problem to set it to anything other than self.default_step
|
# It should be no problem to set it to anything other than self.default_step
|
||||||
self.cvparam.radius = self.radius_cand_list.pop()
|
self.cvparam.radius = self.radius_cand_list.pop()
|
||||||
else:
|
else:
|
||||||
self.radius_cand_list = [i for i in range(self.default_radius, self.auto_radius_range[1], self.default_step[0])][1:]
|
self.radius_cand_list = [i for i in range(default_radius, self.auto_radius_range[1], self.default_step[0])][1:]
|
||||||
# self.default_step is defined separately for xy, but radius is shared by xy, so it may be buggy
|
# self.default_step is defined separately for xy, but radius is shared by xy, so it may be buggy
|
||||||
# It should be no problem to set it to anything other than self.default_step
|
# It should be no problem to set it to anything other than self.default_step
|
||||||
self.cvparam.radius = self.radius_cand_list.pop()
|
self.cvparam.radius = self.radius_cand_list.pop()
|
||||||
@ -721,7 +724,9 @@ def HSRAC(self):
|
|||||||
cv2.circle(self.current_image_gray, min_loc, 2, (0, 0, 255),
|
cv2.circle(self.current_image_gray, min_loc, 2, (0, 0, 255),
|
||||||
-1) # the point of the darkest area in the image
|
-1) # the point of the darkest area in the image
|
||||||
try:
|
try:
|
||||||
|
print(radius)
|
||||||
return out_x, out_y, thresh
|
return out_x, out_y, thresh
|
||||||
|
|
||||||
except:
|
except:
|
||||||
return 0, 0, thresh
|
return 0, 0, thresh
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user