From d8493be30e05f1627a1d934e7838ab12e836f541 Mon Sep 17 00:00:00 2001 From: PeterWaIIace Date: Tue, 28 May 2024 23:57:57 +0200 Subject: [PATCH 1/3] [WiP] Adding loading and unloading model --- eyeGestures/eyegestures.py | 9 ++++++++- pyproject.toml | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/eyeGestures/eyegestures.py b/eyeGestures/eyegestures.py index b038fd4..ce43f2d 100644 --- a/eyeGestures/eyegestures.py +++ b/eyeGestures/eyegestures.py @@ -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 @@ -21,9 +22,9 @@ 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 @@ -54,6 +55,12 @@ 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) diff --git a/pyproject.toml b/pyproject.toml index 8955170..66d99e1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,7 +21,7 @@ exclude = [ [project] name = "eyeGestures" -version = "2.0.0" +version = "2.1.0" authors = [ { name="Piotr Walas", email="piotr.walas@eyegestures.com" }, ] From c8585cd475e8928e24a81ba6207d4a6595ed650d Mon Sep 17 00:00:00 2001 From: PeterWaIIace Date: Wed, 5 Jun 2024 01:43:20 +0200 Subject: [PATCH 2/3] updating gestures --- eyeGestures/eyegestures.py | 13 ++++++++++--- pyproject.toml | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/eyeGestures/eyegestures.py b/eyeGestures/eyegestures.py index ce43f2d..a13daa2 100644 --- a/eyeGestures/eyegestures.py +++ b/eyeGestures/eyegestures.py @@ -30,7 +30,7 @@ def __init__(self): 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 @@ -41,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() @@ -106,12 +107,18 @@ 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 = self.getLandmarks(frame,self.calibrate_gestures and self.enable_CN) margin = 10 if classic_point[0] <= margin and self.calibration: diff --git a/pyproject.toml b/pyproject.toml index 66d99e1..ceb4cf2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,7 +21,7 @@ exclude = [ [project] name = "eyeGestures" -version = "2.1.0" +version = "2.2.0" authors = [ { name="Piotr Walas", email="piotr.walas@eyegestures.com" }, ] From 23325bbe438d9dec91ac122bfa35fd503b6ebe2b Mon Sep 17 00:00:00 2001 From: PeterWaIIace Date: Thu, 6 Jun 2024 12:41:16 +0200 Subject: [PATCH 3/3] [Fix] changing V2 to V1 transition in calibration - should fix the problem with jumping cursor --- eyeGestures/eyegestures.py | 18 +++++++++--------- pyproject.toml | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/eyeGestures/eyegestures.py b/eyeGestures/eyegestures.py index a13daa2..4047fbc 100644 --- a/eyeGestures/eyegestures.py +++ b/eyeGestures/eyegestures.py @@ -68,7 +68,7 @@ def getLandmarks(self, frame, calibrate = False): 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 @@ -83,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: @@ -118,17 +118,17 @@ def step(self, frame, calibration, width, height): self.monitor_width = width self.monitor_height = height - classic_point, key_points, blink, fixation = self.getLandmarks(frame,self.calibrate_gestures and self.enable_CN) + 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 @@ -190,7 +190,7 @@ def __init__(self, roi_y, roi_width, roi_height) - + self.calibrators = dict() self.calibrate = False diff --git a/pyproject.toml b/pyproject.toml index ceb4cf2..98f28b6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,7 +21,7 @@ exclude = [ [project] name = "eyeGestures" -version = "2.2.0" +version = "2.3.0" authors = [ { name="Piotr Walas", email="piotr.walas@eyegestures.com" }, ]