From a47b746962f174b28145a3b0b8708a34419e513c Mon Sep 17 00:00:00 2001 From: Prohurtz <48768484+RedHawk989@users.noreply.github.com> Date: Thu, 19 Jan 2023 20:02:45 -0600 Subject: [PATCH] add beginnings of intensity openness --- EyeTrackApp/hsrac.py | 6 ++- EyeTrackApp/intensity_eye_open.py | 71 +++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 EyeTrackApp/intensity_eye_open.py diff --git a/EyeTrackApp/hsrac.py b/EyeTrackApp/hsrac.py index 3cf1a93..7213007 100644 --- a/EyeTrackApp/hsrac.py +++ b/EyeTrackApp/hsrac.py @@ -1033,6 +1033,8 @@ class HSRAC_cls(object): lower_y = center_y - 20 # Crop the image using the calculated bounds cropped_image = frame[lower_y:upper_y, lower_x:upper_x] + intensity = np.sum(cropped_image) + print(intensity) # frame = cropped_image if self.now_modeo == self.cv_modeo[0] or self.now_modeo == self.cv_modeo[1]: @@ -1080,7 +1082,9 @@ class HSRAC_cls(object): upper_y = center_y + 20 lower_y = center_y - 20 # Crop the image using the calculated bounds - cropped_imagecc = frame[lower_y:upper_y, lower_x:upper_x] + cropped_image = frame[lower_y:upper_y, lower_x:upper_x] + intensity = np.sum(cropped_image) + print(intensity) # frame = cropped_image # if imshow_enable or save_video: # cv2.circle(frame, (orig_x, orig_y), 6, (0, 255, 255), -1) diff --git a/EyeTrackApp/intensity_eye_open.py b/EyeTrackApp/intensity_eye_open.py new file mode 100644 index 0000000..cfb05ac --- /dev/null +++ b/EyeTrackApp/intensity_eye_open.py @@ -0,0 +1,71 @@ +import pandas as pd +import numpy as np +import cv2 + +#higher intensity means more closed/ more white/less pupil + +# HOW THIS WORKS: +# Here is my idea: +# we get the intensity of pupil area from HSF crop, When the eyelid starts to close, the pupil starts being obstructed by skin which is generally lighter than the pupil. +# This causes the intensity to increase. We save all of the darkest intensities of each pupil position to calculate for pupil movement. +# ex. when you look up there is less pupil visible, which results in an uncalculated change in intensity even though the eyelid has not moved in a meaningful way. +# We compare the darkest intensity of that area, to the lightest (global) intensity to find the appropriate openness state via a float. +fname = "test_list.txt" +data = pd.read_csv(fname, sep=",") + +print (data) +xy = 69 + +def intense(x, y, frame): + xy = int(str(x) + str(y)) + intensity = np.sum(frame) + print(intensity) + + try: + dfb = data[data['xy']==xy].index.values.astype(int)[0] # find pandas index of line with matching xy value + + if intensity < data.at[dfb, 'intensity']: #if current intensity value is less (more pupil), save that + data.at[dfb, 'intensity'] = intensity # set value + data.to_csv(fname, encoding='utf-8', index=False) #save file since we made a change + + if intensity > data.at[0, 'intensity']: #if current intensity value is more (less pupil), save that NOTE: we have the + data.at[0, 'intensity'] = intensity # set value + data.to_csv(fname, encoding='utf-8', index=False) #save file since we made a change + + + #e = data.at[dfb,'intensity'] #find intensity with value + + except: # that value is not yet saved + data.loc[len(data.index)] = [xy, intensity] #create new data on last line of csv with current intesity + data.to_csv(fname, encoding='utf-8', index=False) #save file since we made a change + + #data.at[dfb, 'intensity'] = 4 # set value + + #data.to_csv(fname, encoding='utf-8', index=False) #save file + + + #data.loc[len(data.index)] = [xy, intensity] + + return + +vid = cv2.VideoCapture("http://192.168.1.43:4747/video") +x = int(input("x")) +y = int(input("y")) +while(True): + + ret, frame = vid.read() + + cv2.imshow('frame', frame) + upper_x = x + 20 + lower_x = x - 20 + upper_y = y + 20 + lower_y = y - 20 + + cropped_image = frame[lower_y:upper_y, lower_x:upper_x] + intense(x,y, cropped_image) + + if cv2.waitKey(1) & 0xFF == ord('q'): + break + +vid.release() +cv2.destroyAllWindows() \ No newline at end of file