Skip to content

Commit

Permalink
Merge pull request #15 from NativeSensors/develop
Browse files Browse the repository at this point in the history
Syncing Main with latest develop changes
  • Loading branch information
PeterWaIIace authored Jun 6, 2024
2 parents 2441045 + 23325bb commit 9d95d4b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
38 changes: 26 additions & 12 deletions eyeGestures/eyegestures.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from eyeGestures.gevent import Gevent, Cevent
from eyeGestures.utils import timeit
import numpy as np
import pickle
import cv2

import random
Expand All @@ -21,15 +22,15 @@ class EyeGestures_v2:
ACCEPTANCE_RADIUS = 500
CALIBRATION_RADIUS = 1000
EYEGESTURES_CALIBRATION_THRESH = 850
EYEGESTURES_CALIBRATION_FILENAME = 'eygestures_calib.eyec'

def __init__(self):

self.monitor_width = 1
self.monitor_height = 1

self.clb = Calibrator_v2()
self.cap = None
self.gestures = EyeGestures_v1(285,115,40,15)
self.gestures = EyeGestures_v1(285,115,200,100)

self.calibration = False

Expand All @@ -40,7 +41,8 @@ def __init__(self):

self.average_points = np.zeros((20,2))
self.filled_points = 0
self.calibrate_gestures = True
self.enable_CN = False
self.calibrate_gestures = False
self.calibrationMat = CalibrationMatrix()
self.fit_point = self.calibrationMat.getNextPoint()

Expand All @@ -54,13 +56,19 @@ def __init__(self):
# after corssing this thresh we are disabling classical calib
self.eyegestures_calibration_threshold = self.EYEGESTURES_CALIBRATION_THRESH

def saveModel(self):
return pickle.dumps(self.clb)

def loadModel(self,model):
self.clb = pickle.loads(model)

def getLandmarks(self, frame, calibrate = False):

frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
frame = cv2.flip(frame,1)
# frame = cv2.resize(frame, (360, 640))

event, _ = self.gestures.step(
event, cevent = self.gestures.step(
frame,
"main",
calibrate, # set calibration - switch to False to stop calibration
Expand All @@ -75,7 +83,7 @@ def getLandmarks(self, frame, calibrate = False):
cursors = np.array([cursor_x,cursor_y]).reshape(1, 2)
eye_events = np.array([event.blink,event.fixation]).reshape(1, 2)
key_points = np.concatenate((cursors,l_eye_landmarks,r_eye_landmarks,eye_events))
return np.array((cursor_x, cursor_y)), key_points, event.blink, event.fixation
return np.array((cursor_x, cursor_y)), key_points, event.blink, event.fixation, cevent

def increase_precision(self):
if self.acceptance_radius > self.precision_limit:
Expand All @@ -99,22 +107,28 @@ def setFixation(self,fix):
def setClassicalImpact(self,CN):
self.CN = CN

def enableCNCalib(self):
self.enable_CN = True

def disableCNCalib(self):
self.enable_CN = False

def step(self, frame, calibration, width, height):
self.calibration = calibration
self.monitor_width = width
self.monitor_height = height

classic_point, key_points, blink, fixation = self.getLandmarks(frame,self.calibrate_gestures)
classic_point, key_points, blink, fixation, cevent = self.getLandmarks(frame,self.calibrate_gestures and self.enable_CN)

margin = 10
if classic_point[0] <= margin and self.calibration:
self.calibrate_gestures = True
self.calibrate_gestures = cevent.calibration
elif classic_point[0] >= width - margin and self.calibration:
self.calibrate_gestures = True
elif classic_point[1] <= margin and self.calibration:
self.calibrate_gestures = True
self.calibrate_gestures = cevent.calibration
elif cevent.point[1] <= margin and self.calibration:
self.calibrate_gestures = cevent.calibration
elif classic_point[1] >= height - margin and self.calibration:
self.calibrate_gestures = True
self.calibrate_gestures = cevent.calibration
else:
self.calibrate_gestures = False

Expand Down Expand Up @@ -176,7 +190,7 @@ def __init__(self,
roi_y,
roi_width,
roi_height)

self.calibrators = dict()
self.calibrate = False

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ exclude = [

[project]
name = "eyeGestures"
version = "2.0.0"
version = "2.3.0"
authors = [
{ name="Piotr Walas", email="[email protected]" },
]
Expand Down

0 comments on commit 9d95d4b

Please sign in to comment.