Skip to content

Commit

Permalink
adding automatic calibrator
Browse files Browse the repository at this point in the history
  • Loading branch information
Wallace committed Feb 21, 2024
1 parent 4e2c876 commit ab0373a
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 48 deletions.
88 changes: 80 additions & 8 deletions PupilLab.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,71 @@

from screeninfo import get_monitors

class Calibrator:

def __init__(self):
self.calibrator = dict()
pass

def get(self, id):
if id not in self.calibrator.keys():
return False
return self.calibrator[id]["calibration"]
pass

def create(self,id,monitor):
if id not in self.calibrator.keys():
self.calibrator[id] = {
"calibration": False ,
"monitor" : monitor ,
"left" : 0 ,
"right" : 0 ,
"up" : 0 ,
"down" : 0
}

def check(self,id,screen_point):
margin = 5
width = self.calibrator[id]["monitor"].width
height = self.calibrator[id]["monitor"].height
x = screen_point[0] - self.calibrator[id]["monitor"].x
y = screen_point[1] - self.calibrator[id]["monitor"].y

print(f"{x} {y} {width} {height}")
if x <= margin:
self.calibrator[id]["left"] += 1
else:
self.calibrator[id]["left"] = 0

if width - margin <= x:
self.calibrator[id]["right"] += 1
else:
self.calibrator[id]["right"] = 0

if y <= margin:
self.calibrator[id]["up"] += 1
else:
self.calibrator[id]["up"] = 0

if height - margin <= y:
self.calibrator[id]["down"] += 1
else:
self.calibrator[id]["down"] = 0


if (self.calibrator[id]["left"] > 20 or
self.calibrator[id]["right"] > 20 or
self.calibrator[id]["up"] > 20 or
self.calibrator[id]["down"] > 20):
self.calibrator[id]["left"] = 0
self.calibrator[id]["right"] = 0
self.calibrator[id]["up"] = 0
self.calibrator[id]["down"] = 0
self.calibrator[id]["calibration"] = True
else:
self.calibrator[id]["calibration"] = False


def rotate(point,face):

(x,y) = point
Expand Down Expand Up @@ -82,7 +147,8 @@ def __init__(self):

self.worker = Worker(self.run)
self.prev_event = None
self.calibration = False

self.calibrator = Calibrator()

def on_button(self,key):
if not hasattr(key,'char'):
Expand All @@ -93,13 +159,13 @@ def on_button(self,key):
self.dot_widget.close_event()
self.cap.close()

if key.char == 'c':
print("Calibration stop")
self.calibration = False
# if key.char == 'c':
# print("Calibration stop")
# self.calibration = False

if key.char == 's':
print("Calibration start")
self.calibration = True
# if key.char == 's':
# print("Calibration start")
# self.calibration = True

def __display_clusters(self,whiteboardPupil,buffor):

Expand Down Expand Up @@ -176,10 +242,14 @@ def __display_eye(self,frame):
frame = cv2.flip(frame, 1)

self.monitor = list(filter(lambda monitor: monitor.is_primary == True ,get_monitors()))[0]

self.calibrator.create("main",self.monitor)
calibration = self.calibrator.get("main")

event = self.gestures.estimate(
frame,
"main",
self.calibration,
calibration ,
self.monitor.width,
self.monitor.height,
self.monitor.x,
Expand All @@ -189,6 +259,8 @@ def __display_eye(self,frame):
self.prev_event = event

if not event is None:
self.calibrator.check("main",event.point_screen)

print(f"event.point_screen: {event.point_screen}")
self.frame_counter += 1

Expand Down
14 changes: 1 addition & 13 deletions eyeGestures/gazeEstimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
from eyeGestures.screenTracker.screenTracker import ScreenManager
import eyeGestures.screenTracker.dataPoints as dp

def isInside(circle_x, circle_y, r, x, y):

def isInside(circle_x, circle_y, r, x, y):
# Compare radius of circle
# with distance of its center
# from given point
Expand Down Expand Up @@ -40,7 +39,6 @@ def __init__(self,
self.r_eye = r_eye
self.screen_man = screen_man
self.context = context

class Fixation:

def __init__(self,x,y,radius = 100):
Expand Down Expand Up @@ -93,16 +91,6 @@ def __init__(self,screen_width,screen_heigth,
self.GContext = GazeContext()
# self.calibration = False

# def freeze_calibration(self):
# self.calibration = False
# pass
# # self.screen_man.freeze_calibration()

# def unfreeze_calibration(self):
# self.calibration = True
# pass
# # self.screen_man.unfreeze_calibration()

def __gaze_intersection(self,l_eye,r_eye):
l_pupil = l_eye.getPupil()
l_gaze = l_eye.getGaze()
Expand Down
27 changes: 0 additions & 27 deletions eyeGestures/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,30 +69,3 @@ def getAvgPupil(self,width = None, height = None):
return _retPupil

## main code:

# self.eyeDisplay.update(face,250,250)
# self.eyeDisplay.draw(whiteboard,image,250,250)
# self.pupilLab.imshow(
# self.__convertFrame(whiteboard))

###################################################################################3
# get center:
# whiteboardAdj = np.full((250,250,3),255.0,dtype = np.uint8)


# point = self.pupilBuffor.getAvg()
# x = int(((point[0])/30 - 3.5)*1920)
# y = int(((point[1])/30)*1080)
# self.red_dot_widget.move(x,y)
# print(f"move: {x,y} offset: {min_x,width}")

# # openness need to be calculated relatively to 250x250 frame
# print(f"openness of the eyes: {height} width: {width} scale: {height/width - 0.25}")
# # 0.40 > wide open
# # 0.30 > normally open - looking up or so
# # 0.20 > sligthly closed - looking down

# print(f"vision map: {vision_map_start} {vision_map_wh} {vision_map_end}")
# cv2.rectangle(whiteboardAdj,vision_map_start,vision_map_end,(255,0,0),1)


0 comments on commit ab0373a

Please sign in to comment.