minor optimization and fixes

This commit is contained in:
Prohurtz 2023-01-30 21:14:21 -06:00
parent 4e8db0d0d0
commit b3c214d5ce
3 changed files with 30 additions and 23 deletions

View File

@ -246,7 +246,7 @@ class EyeProcessor:
def HSRACM(self):
cx, cy, thresh, gray_frame = External_Run_HSRACS.HSRACS(self)
cx, cy, thresh, gray_frame, uncropframe = External_Run_HSRACS.HSRACS(self)
self.current_image_gray = gray_frame
if self.prev_x == None:
self.prev_x = cx
@ -256,7 +256,7 @@ class EyeProcessor:
# if (cx - self.prev_x) <= 45 and (cy - self.prev_y) <= 45 :
# self.prev_x = cx
# self.prev_y = cy
eyeopen = intense(cx, cy, self.current_image_gray)
eyeopen = intense(cx, cy, uncropframe)
out_x, out_y = cal_osc(self, cx, cy)
if cx == 0:

View File

@ -669,7 +669,7 @@ class CenterCorrection(object):
video_path = "demo2.mp4"
imshow_enable = False
imshow_enable = True
save_video = False
thresh_add = 10
@ -1089,12 +1089,14 @@ class HSRAC_cls(object):
# print('Kernel response:', response)
# print('Pixel position:', center_xy)
if imshow_enable:
if self.now_modeo != self.cv_modeo[0] and self.now_modeo != self.cv_modeo[1]:
if 0 in cropped_image.shape:
# If shape contains 0, it is not detected well.
pass
else:
cv2.imshow("crop", cropped_image)
cv2.imshow("frame", frame)
if cv2.waitKey(1) & 0xFF == ord("q"):
@ -1181,8 +1183,12 @@ class HSRAC_cls(object):
csx = frame.shape[0]
csy = frame.shape[1]
cx = center_x - (csx - cx) # we find the difference between the crop size and ransac point, and subtract from the center point from HSF
cy = center_y - (csy - cy)
#cx = center_x - (csx - cx) # we find the difference between the crop size and ransac point, and subtract from the center point from HSF
# cy = center_y - (csy - cy)
cx = (cx - 20) + center_x
cy = (cy - 20) + center_y
cv_end_time = timeit.default_timer()
@ -1196,13 +1202,12 @@ class HSRAC_cls(object):
pass
# print(frame_gray.shape, thresh.shape)
try:
return cx, cy, thresh, frame
return cx, cy, thresh, frame, gray_frame
except:
return center_x, center_y, thresh, frame
return center_x, center_y, thresh, frame, gray_frame
class External_Run_HSRACS:
@ -1210,8 +1215,9 @@ class External_Run_HSRACS:
def HSRACS(self):
External_Run_HSRACS.hsrac.current_image_gray = self.current_image_gray
center_x, center_y, thresh, frame = External_Run_HSRACS.hsrac.single_run()
return center_x, center_y, thresh, frame
center_x, center_y, thresh, frame, gray_frame = External_Run_HSRACS.hsrac.single_run()
return center_x, center_y, thresh, frame, gray_frame
if __name__ == '__main__':
hsrac = HSRAC_cls()

View File

@ -1,8 +1,6 @@
import pandas as pd
import numpy as np
import cv2
from pythonosc import udp_client
import time
#higher intensity means more closed/ more white/less pupil
#Hm I need an acronym for this, any ideas?
@ -16,7 +14,7 @@ from pythonosc import udp_client
# We compare the darkest intensity of that area, to the lightest (global) intensity to find the appropriate openness state via a float.
fname = "IBO.csv" #TODO Expose as setting
lct = time.time()
try:
data = pd.read_csv(fname, sep=",")
except:
@ -28,11 +26,12 @@ except:
#TODO we need more pixel points for smooth operation, lets get this setup in hsrac
def intense(x, y, frame):
# upper_x = x + 25
# lower_x = x - 25
# upper_y = y + 25
# lower_y = y - 25
# frame = frame[lower_y:upper_y, lower_x:upper_x]
global lct
upper_x = int(x) + 25 #TODO make this a setting
lower_x = int(x) - 25
upper_y = int(y) + 25
lower_y = int(y) - 25
frame = frame[lower_y:upper_y, lower_x:upper_x]
try:
xy = int(str(int(x)) + str(int(y)) + str(int(x)+int(y)))
@ -73,7 +72,6 @@ def intense(x, y, frame):
data.at[0, 'intensity'] = intensity # set value at 0 index
changed = True
print("create max", intensity)
try:
maxp = data.at[dfb, 'intensity']
minp = data.at[0, 'intensity']
@ -82,12 +80,15 @@ def intense(x, y, frame):
eyeopen = 1 - eyeopen
# print(intensity, maxp, minp, x, y)
print(f"EYEOPEN: {eyeopen}")
except:
print('[INFO] Something went wrong, assuming blink.')
eyeopen = 0.0
if changed == True:
if changed == True and ((time.time() - lct) > 4): #save every 4 seconds if something changed to save disk usage
data.to_csv(fname, encoding='utf-8', index=False) #save file since we made a change
lct = time.time()
print("SAVED")
return eyeopen