From 8f2709253c8bc6106ec59c9771e1f54d94370ce2 Mon Sep 17 00:00:00 2001 From: Prohurtz <48768484+RedHawk989@users.noreply.github.com> Date: Sat, 23 Sep 2023 17:26:19 -0500 Subject: [PATCH] fix blink algo crash, do not resize small frames --- EyeTrackApp/blink.py | 42 +++++++++++++++++++++--------------------- EyeTrackApp/camera.py | 8 ++++---- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/EyeTrackApp/blink.py b/EyeTrackApp/blink.py index a098f17..86ce31e 100644 --- a/EyeTrackApp/blink.py +++ b/EyeTrackApp/blink.py @@ -17,27 +17,27 @@ def BLINK(self): else: self.filterlist.pop(0) self.filterlist.append(intensity) + if intensity >= np.percentile(self.filterlist, 99) or intensity <= np.percentile(self.filterlist, 1) and len(self.max_ints) >= 1: # filter abnormally high values + try: # I don't want this here but I cant get python to stop crying when it's not + intensity = min(self.max_ints) + except: + pass - if intensity >= np.percentile(self.filterlist, 99) or intensity <= np.percentile(self.filterlist, 1): # filter abnormally high values - # print('filter, assume blink') - intensity = min(self.max_ints) + self.frames = self.frames + 1 + if intensity > self.max_int: + self.max_int = intensity + if self.frames > 300: #TODO: test this number more (make it a setting??) + self.max_ints.append(self.max_int) + if intensity < self.min_int: + self.min_int = intensity - - # self.frames = self.frames + 1 -# if intensity > self.max_int: - # self.max_int = intensity - #@ if self.frames > 300: #TODO: test this number more (make it a setting??) - # 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): - # blinkvalue = 0.0 - # else: - # blinkvalue = 0.7 - #try: - # return blinkvalue - # except: - # return 0.7 + if len(self.max_ints) > 1: + if intensity > min(self.max_ints): + blinkvalue = 0.0 + else: + blinkvalue = 0.7 + try: + return blinkvalue + except: + return 0.7 # print(self.blinkvalue, self.max_int, self.min_int, self.frames, intensity) \ No newline at end of file diff --git a/EyeTrackApp/camera.py b/EyeTrackApp/camera.py index 011b87b..0ee6e9c 100644 --- a/EyeTrackApp/camera.py +++ b/EyeTrackApp/camera.py @@ -139,10 +139,10 @@ class Camera: try: ret, image = self.cv2_camera.read() height, width = image.shape[:2] # Calculate the aspect ratio - aspect_ratio = float(width) / float(height) # Determine the new height based on the desired maximum width - new_height = int(680 / aspect_ratio) - image = cv2.resize(image, (680, new_height)) - # image = cv2.resize(image, (480, 480)) + if int(width) > 680: + aspect_ratio = float(width) / float(height) # Determine the new height based on the desired maximum width + new_height = int(680 / aspect_ratio) + image = cv2.resize(image, (680, new_height)) if not ret: self.cv2_camera.set(cv2.CAP_PROP_POS_FRAMES, 0) raise RuntimeError("Problem while getting frame")