feat: remove rotation slider on main page

This commit is contained in:
Prohurtz 2024-08-18 17:52:23 -05:00
parent 6024a67fc8
commit db78c951a6
3 changed files with 23 additions and 41 deletions

View File

@ -165,17 +165,6 @@ class CameraWidget:
tooltip="Go here to crop out your eye.", tooltip="Go here to crop out your eye.",
), ),
], ],
[
sg.Text("Rotation", background_color="#424042"),
sg.Slider(
range=(0, 360),
default_value=self.config.rotation_angle,
orientation="h",
key=self.gui_rotation_slider,
background_color="#424042",
tooltip="Adjust the rotation of your cameras, make them level.",
),
],
[ [
sg.Column( sg.Column(
self.tracking_layout, self.tracking_layout,
@ -206,6 +195,15 @@ class CameraWidget:
# button_color="#6f4ca1", # button_color="#6f4ca1",
# tooltip="Lighten shadowed areas.", # tooltip="Lighten shadowed areas.",
# ), # ),
sg.Text("Rotation", background_color="#424042"),
sg.Slider(
range=(0, 360),
default_value=self.config.rotation_angle,
orientation="h",
key=self.gui_rotation_slider,
background_color="#424042",
tooltip="Adjust the rotation of your cameras, make them level.",
),
sg.Checkbox( sg.Checkbox(
"Camera Widget Padding", "Camera Widget Padding",
default=self.config.gui_rotation_ui_padding, default=self.config.gui_rotation_ui_padding,

View File

@ -34,6 +34,7 @@ import cv2
from eye import EyeId from eye import EyeId
from one_euro_filter import OneEuroFilter from one_euro_filter import OneEuroFilter
os.environ["OMP_NUM_THREADS"] = "1" os.environ["OMP_NUM_THREADS"] = "1"
# Note. # Note.
@ -65,9 +66,7 @@ def data2csv(data_u32, filepath):
# For data checking # For data checking
nonzero_index = np.nonzero(data_u32) # (row,col) nonzero_index = np.nonzero(data_u32) # (row,col)
data_list = data_u32[nonzero_index].tolist() data_list = data_u32[nonzero_index].tolist()
datalines = [ datalines = ["{},{},{}\n".format(x, y, val) for y, x, val in zip(*nonzero_index, data_list)]
"{},{},{}\n".format(x, y, val) for y, x, val in zip(*nonzero_index, data_list)
]
with open(filepath, "w", encoding="utf-8") as out_f: with open(filepath, "w", encoding="utf-8") as out_f:
out_f.write("x,y,eyedilation\n") out_f.write("x,y,eyedilation\n")
out_f.writelines(datalines) out_f.writelines(datalines)
@ -87,9 +86,7 @@ def u32_1ch_to_u16_3ch(img):
def u16_3ch_to_u32_1ch(img): def u16_3ch_to_u32_1ch(img):
# The image format with the most bits that can be displayed on Windows without additional software and that opencv can handle is PNG's uint16 # The image format with the most bits that can be displayed on Windows without additional software and that opencv can handle is PNG's uint16
out = img[:, :, 0].astype(np.float64) # float64 = max 2^53 out = img[:, :, 0].astype(np.float64) # float64 = max 2^53
cv2.add( cv2.add(out, img[:, :, 1].astype(np.float64) * np.float64(65536), dst=out) # opencv did not have uint32 type
out, img[:, :, 1].astype(np.float64) * np.float64(65536), dst=out
) # opencv did not have uint32 type
return out.astype(np.uint32) # cast return out.astype(np.uint32) # cast
@ -137,9 +134,7 @@ class EllipseBasedPupilDilation:
min_cutoff = 0.00001 min_cutoff = 0.00001
beta = 0.05 beta = 0.05
noisy_point = np.array([1, 1]) noisy_point = np.array([1, 1])
self.one_euro_filter = OneEuroFilter( self.one_euro_filter = OneEuroFilter(noisy_point, min_cutoff=min_cutoff, beta=beta)
noisy_point, min_cutoff=min_cutoff, beta=beta
)
def check(self, frameshape): def check(self, frameshape):
# 0 in data is used as the initial value. # 0 in data is used as the initial value.
@ -154,9 +149,7 @@ class EllipseBasedPupilDilation:
# Not very clever, but increase the width by 1px to save the maximum value. # Not very clever, but increase the width by 1px to save the maximum value.
frameshape = (frameshape[0], frameshape[1] + 1) frameshape = (frameshape[0], frameshape[1] + 1)
if self.data is None: if self.data is None:
print( print(f"\033[92m[INFO] Loaded data for pupil dilation: {self.imgfile}\033[0m")
f"\033[92m[INFO] Loaded data for pupil dilation: {self.imgfile}\033[0m"
)
if os.path.isfile(self.imgfile): if os.path.isfile(self.imgfile):
try: try:
img = cv2.imread(self.imgfile, flags=cv2.IMREAD_UNCHANGED) img = cv2.imread(self.imgfile, flags=cv2.IMREAD_UNCHANGED)
@ -179,9 +172,7 @@ class EllipseBasedPupilDilation:
print("\033[94m[INFO] File does not exist.\033[0m") print("\033[94m[INFO] File does not exist.\033[0m")
req_newdata = True req_newdata = True
else: else:
if self.data.shape != frameshape or not np.array_equal( if self.data.shape != frameshape or not np.array_equal(self.img_roi, self.now_roi):
self.img_roi, self.now_roi
):
# If the ROI recorded in the image file differs from the current ROI # If the ROI recorded in the image file differs from the current ROI
# todo: Using the previous and current frame sizes and centre positions from the original, etc., the data can be ported to some extent, but there may be many areas where code changes are required. # todo: Using the previous and current frame sizes and centre positions from the original, etc., the data can be ported to some extent, but there may be many areas where code changes are required.
print("[INFO] \033[94mFrame size changed.\033[0m") print("[INFO] \033[94mFrame size changed.\033[0m")
@ -242,9 +233,7 @@ class EllipseBasedPupilDilation:
self.filterlist.append(pupil_area) self.filterlist.append(pupil_area)
try: try:
if pupil_area >= np.percentile( if pupil_area >= np.percentile(self.filterlist, 99): # filter abnormally high values
self.filterlist, 98
): # filter abnormally high values
# print('filter, assume blink') # print('filter, assume blink')
pupil_area = self.maxval pupil_area = self.maxval
@ -306,9 +295,7 @@ class EllipseBasedPupilDilation:
changed = True changed = True
newval_flg = True newval_flg = True
else: else:
if ( if pupil_area < data_val: # if current intensity value is less (more pupil), save that
pupil_area < data_val
): # if current intensity value is less (more pupil), save that
self.data[int_y, int_x] = pupil_area # set value self.data[int_y, int_x] = pupil_area # set value
changed = True changed = True
else: else:
@ -322,9 +309,7 @@ class EllipseBasedPupilDilation:
if self.maxval == 0: # that value is not yet saved if self.maxval == 0: # that value is not yet saved
self.maxval = pupil_area # set value at 0 index self.maxval = pupil_area # set value at 0 index
else: else:
if ( if pupil_area > self.maxval: # if current intensity value is more (less pupil), save that NOTE: we have the
pupil_area > self.maxval
): # if current intensity value is more (less pupil), save that NOTE: we have the
self.maxval = pupil_area - 5 # set value at 0 index self.maxval = pupil_area - 5 # set value at 0 index
else: else:
pupil_aread = max( pupil_aread = max(
@ -332,6 +317,7 @@ class EllipseBasedPupilDilation:
) # continuously adjust closed intensity, will be set when user blink, used to allow eyes to close when lighting changes ) # continuously adjust closed intensity, will be set when user blink, used to allow eyes to close when lighting changes
self.maxval = pupil_aread # set value at 0 index self.maxval = pupil_aread # set value at 0 index
# print(intensityd, intensity) # print(intensityd, intensity)
if newval_flg: if newval_flg:
# Do the same thing as in the original version. # Do the same thing as in the original version.
eyedilation = self.prev_val # 0.9 eyedilation = self.prev_val # 0.9
@ -344,6 +330,7 @@ class EllipseBasedPupilDilation:
eyedilation = 0.5 eyedilation = 0.5
else: else:
eyedilation = (pupil_area - maxp) / (minp - maxp) eyedilation = (pupil_area - maxp) / (minp - maxp)
# print(eyedilation, pupil_area, maxp, minp)
except: except:
eyedilation = 0.5 eyedilation = 0.5
eyedilation = 1 - eyedilation eyedilation = 1 - eyedilation
@ -362,17 +349,13 @@ class EllipseBasedPupilDilation:
if eyedilation < 0: if eyedilation < 0:
eyedilation = 0.0 eyedilation = 0.0
if changed and ( if changed and ((time.time() - self.lct) > 15): # save every 5 seconds if something changed to save disk usage
(time.time() - self.lct) > 15
): # save every 5 seconds if something changed to save disk usage
self.save() self.save()
self.lct = time.time() self.lct = time.time()
self.prev_val = eyedilation self.prev_val = eyedilation
try: try:
noisy_point = np.array( noisy_point = np.array([float(eyedilation), float(eyedilation)]) # fliter our values with a One Euro Filter
[float(eyedilation), float(eyedilation)]
) # fliter our values with a One Euro Filter
point_hat = self.one_euro_filter(noisy_point) point_hat = self.one_euro_filter(noisy_point)
eyedilationx = point_hat[0] eyedilationx = point_hat[0]
eyedilationy = point_hat[1] eyedilationy = point_hat[1]

View File

@ -317,6 +317,7 @@ class IntensityBasedOpeness:
) # continuously adjust closed intensity, will be set when user blink, used to allow eyes to close when lighting changes ) # 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 self.maxval = intensityd # set value at 0 index
# print(intensityd, intensity) # print(intensityd, intensity)
if newval_flg: if newval_flg:
# Do the same thing as in the original version. # Do the same thing as in the original version.
eyeopen = self.prev_val # 0.9 eyeopen = self.prev_val # 0.9