aboutsummaryrefslogtreecommitdiff
path: root/src/argaze/GazeAnalysis/LinearRegression.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/argaze/GazeAnalysis/LinearRegression.py')
-rw-r--r--src/argaze/GazeAnalysis/LinearRegression.py27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/argaze/GazeAnalysis/LinearRegression.py b/src/argaze/GazeAnalysis/LinearRegression.py
index 5a92048..de7725d 100644
--- a/src/argaze/GazeAnalysis/LinearRegression.py
+++ b/src/argaze/GazeAnalysis/LinearRegression.py
@@ -31,9 +31,11 @@ class GazePositionCalibrator(GazeFeatures.GazePositionCalibrator):
"""Linear regression intercept value"""
def __post_init__(self):
- """Init calibration data."""
+ """Init calibration."""
- self.reset()
+ self.__linear_regression = LinearRegression()
+ self.__linear_regression.coef_ = numpy.array(self.coefficients)
+ self.__linear_regression.intercept_ = numpy.array(self.intercept)
def store(self, timestamp: int|float, observed_gaze_position: GazeFeatures.GazePosition, expected_gaze_position: GazeFeatures.GazePosition):
"""Store observed and expected gaze positions."""
@@ -57,12 +59,25 @@ class GazePositionCalibrator(GazeFeatures.GazePositionCalibrator):
self.__linear_regression = LinearRegression().fit(self.__observed_positions, self.__expected_positions)
+ # Update frozen coefficients attribute
+ object.__setattr__(self, 'coefficients', self.__linear_regression.coef_)
+
+ # Update frozen intercept attribute
+ object.__setattr__(self, 'intercept', self.__linear_regression.intercept_)
+
+ # Return calibrated gaze position
return self.__linear_regression.score(self.__observed_positions, self.__expected_positions)
def apply(self, gaze_position: GazeFeatures.GazePosition) -> GazePositionType:
"""Apply calibration onto observed gaze position."""
- return GazeFeatures.GazePosition(self.__linear_regression.predict(numpy.array([gaze_position.value]))[0], precision=gaze_position.precision)
+ if not self.calibrating:
+
+ return GazeFeatures.GazePosition(self.__linear_regression.predict(numpy.array([gaze_position.value]))[0], precision=gaze_position.precision)
+
+ else:
+
+ return gaze_position
def draw(self, image: numpy.array):
"""Draw calibration into image.
@@ -74,7 +89,7 @@ class GazePositionCalibrator(GazeFeatures.GazePositionCalibrator):
raise NotImplementedError('draw() method not implemented')
@property
- def ready(self) -> bool:
- """Is the calibrator ready?"""
+ def calibrating(self) -> bool:
+ """Is the calibration running?"""
- return self.__linear_regression is not None \ No newline at end of file
+ return self.__linear_regression is None \ No newline at end of file