fix blink algo crash, do not resize small frames

This commit is contained in:
Prohurtz 2023-09-23 17:26:19 -05:00
parent 58a86f158f
commit 8f2709253c
2 changed files with 25 additions and 25 deletions

View File

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

View File

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