mirror of
https://github.com/EyeTrackVR/EyeTrackVR.git
synced 2025-11-04 14:39:42 +08:00
minor optimization and fixes
This commit is contained in:
parent
4e8db0d0d0
commit
b3c214d5ce
@ -246,7 +246,7 @@ class EyeProcessor:
|
|||||||
|
|
||||||
|
|
||||||
def HSRACM(self):
|
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
|
self.current_image_gray = gray_frame
|
||||||
if self.prev_x == None:
|
if self.prev_x == None:
|
||||||
self.prev_x = cx
|
self.prev_x = cx
|
||||||
@ -256,7 +256,7 @@ class EyeProcessor:
|
|||||||
# if (cx - self.prev_x) <= 45 and (cy - self.prev_y) <= 45 :
|
# if (cx - self.prev_x) <= 45 and (cy - self.prev_y) <= 45 :
|
||||||
# self.prev_x = cx
|
# self.prev_x = cx
|
||||||
# self.prev_y = cy
|
# 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)
|
out_x, out_y = cal_osc(self, cx, cy)
|
||||||
|
|
||||||
if cx == 0:
|
if cx == 0:
|
||||||
|
|||||||
@ -669,7 +669,7 @@ class CenterCorrection(object):
|
|||||||
|
|
||||||
|
|
||||||
video_path = "demo2.mp4"
|
video_path = "demo2.mp4"
|
||||||
imshow_enable = False
|
imshow_enable = True
|
||||||
save_video = False
|
save_video = False
|
||||||
|
|
||||||
thresh_add = 10
|
thresh_add = 10
|
||||||
@ -1089,12 +1089,14 @@ class HSRAC_cls(object):
|
|||||||
# print('Kernel response:', response)
|
# print('Kernel response:', response)
|
||||||
# print('Pixel position:', center_xy)
|
# print('Pixel position:', center_xy)
|
||||||
|
|
||||||
|
|
||||||
if imshow_enable:
|
if imshow_enable:
|
||||||
if self.now_modeo != self.cv_modeo[0] and self.now_modeo != self.cv_modeo[1]:
|
if self.now_modeo != self.cv_modeo[0] and self.now_modeo != self.cv_modeo[1]:
|
||||||
if 0 in cropped_image.shape:
|
if 0 in cropped_image.shape:
|
||||||
# If shape contains 0, it is not detected well.
|
# If shape contains 0, it is not detected well.
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
|
||||||
cv2.imshow("crop", cropped_image)
|
cv2.imshow("crop", cropped_image)
|
||||||
cv2.imshow("frame", frame)
|
cv2.imshow("frame", frame)
|
||||||
if cv2.waitKey(1) & 0xFF == ord("q"):
|
if cv2.waitKey(1) & 0xFF == ord("q"):
|
||||||
@ -1181,8 +1183,12 @@ class HSRAC_cls(object):
|
|||||||
csx = frame.shape[0]
|
csx = frame.shape[0]
|
||||||
csy = frame.shape[1]
|
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
|
#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)
|
# cy = center_y - (csy - cy)
|
||||||
|
|
||||||
|
cx = (cx - 20) + center_x
|
||||||
|
cy = (cy - 20) + center_y
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cv_end_time = timeit.default_timer()
|
cv_end_time = timeit.default_timer()
|
||||||
@ -1196,13 +1202,12 @@ class HSRAC_cls(object):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# print(frame_gray.shape, thresh.shape)
|
# print(frame_gray.shape, thresh.shape)
|
||||||
try:
|
try:
|
||||||
return cx, cy, thresh, frame
|
return cx, cy, thresh, frame, gray_frame
|
||||||
except:
|
except:
|
||||||
return center_x, center_y, thresh, frame
|
return center_x, center_y, thresh, frame, gray_frame
|
||||||
|
|
||||||
|
|
||||||
class External_Run_HSRACS:
|
class External_Run_HSRACS:
|
||||||
|
|
||||||
@ -1210,8 +1215,9 @@ class External_Run_HSRACS:
|
|||||||
|
|
||||||
def HSRACS(self):
|
def HSRACS(self):
|
||||||
External_Run_HSRACS.hsrac.current_image_gray = self.current_image_gray
|
External_Run_HSRACS.hsrac.current_image_gray = self.current_image_gray
|
||||||
center_x, center_y, thresh, frame = External_Run_HSRACS.hsrac.single_run()
|
center_x, center_y, thresh, frame, gray_frame = External_Run_HSRACS.hsrac.single_run()
|
||||||
return center_x, center_y, thresh, frame
|
return center_x, center_y, thresh, frame, gray_frame
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
hsrac = HSRAC_cls()
|
hsrac = HSRAC_cls()
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
import pandas as pd
|
import pandas as pd
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import cv2
|
import time
|
||||||
from pythonosc import udp_client
|
|
||||||
|
|
||||||
#higher intensity means more closed/ more white/less pupil
|
#higher intensity means more closed/ more white/less pupil
|
||||||
|
|
||||||
#Hm I need an acronym for this, any ideas?
|
#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.
|
# 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
|
fname = "IBO.csv" #TODO Expose as setting
|
||||||
|
lct = time.time()
|
||||||
try:
|
try:
|
||||||
data = pd.read_csv(fname, sep=",")
|
data = pd.read_csv(fname, sep=",")
|
||||||
except:
|
except:
|
||||||
@ -28,11 +26,12 @@ except:
|
|||||||
#TODO we need more pixel points for smooth operation, lets get this setup in hsrac
|
#TODO we need more pixel points for smooth operation, lets get this setup in hsrac
|
||||||
|
|
||||||
def intense(x, y, frame):
|
def intense(x, y, frame):
|
||||||
# upper_x = x + 25
|
global lct
|
||||||
# lower_x = x - 25
|
upper_x = int(x) + 25 #TODO make this a setting
|
||||||
# upper_y = y + 25
|
lower_x = int(x) - 25
|
||||||
# lower_y = y - 25
|
upper_y = int(y) + 25
|
||||||
# frame = frame[lower_y:upper_y, lower_x:upper_x]
|
lower_y = int(y) - 25
|
||||||
|
frame = frame[lower_y:upper_y, lower_x:upper_x]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
xy = int(str(int(x)) + str(int(y)) + str(int(x)+int(y)))
|
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
|
data.at[0, 'intensity'] = intensity # set value at 0 index
|
||||||
changed = True
|
changed = True
|
||||||
print("create max", intensity)
|
print("create max", intensity)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
maxp = data.at[dfb, 'intensity']
|
maxp = data.at[dfb, 'intensity']
|
||||||
minp = data.at[0, 'intensity']
|
minp = data.at[0, 'intensity']
|
||||||
@ -82,12 +80,15 @@ def intense(x, y, frame):
|
|||||||
eyeopen = 1 - eyeopen
|
eyeopen = 1 - eyeopen
|
||||||
# print(intensity, maxp, minp, x, y)
|
# print(intensity, maxp, minp, x, y)
|
||||||
print(f"EYEOPEN: {eyeopen}")
|
print(f"EYEOPEN: {eyeopen}")
|
||||||
|
|
||||||
|
|
||||||
except:
|
except:
|
||||||
print('[INFO] Something went wrong, assuming blink.')
|
print('[INFO] Something went wrong, assuming blink.')
|
||||||
eyeopen = 0.0
|
eyeopen = 0.0
|
||||||
|
if changed == True and ((time.time() - lct) > 4): #save every 4 seconds if something changed to save disk usage
|
||||||
if changed == True:
|
|
||||||
data.to_csv(fname, encoding='utf-8', index=False) #save file since we made a change
|
data.to_csv(fname, encoding='utf-8', index=False) #save file since we made a change
|
||||||
|
lct = time.time()
|
||||||
|
print("SAVED")
|
||||||
|
|
||||||
|
|
||||||
return eyeopen
|
return eyeopen
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user