这是indexloc提供的服务,不要输入任何密码
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"clean": "rimraf dist",
"prebuild": "npm run clean",
"dev": "webpack --progress --config webpack.config.js --mode development",
"watch": "webpack --watch --progress --config webpack.config.js --mode development",
"build": "webpack --progress --config webpack.config.js --mode production",
"gen_docs": "jsdoc -c jsdoc.conf.json src/*"
},
Expand Down
5 changes: 5 additions & 0 deletions src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import TFFaceMesh from './facemesh.mjs';
import Reg from './ridgeReg.mjs';
import ridgeRegWeighted from './ridgeWeightedReg.mjs';
import ridgeRegThreaded from './ridgeRegThreaded.mjs';
import RidgeRegXpln from './ridgeRegXpln.mjs';
import util from './util.mjs';

const webgazer = {};
Expand All @@ -18,6 +19,7 @@ webgazer.tracker.TFFaceMesh = TFFaceMesh;
webgazer.reg = Reg;
webgazer.reg.RidgeWeightedReg = ridgeRegWeighted.RidgeWeightedReg;
webgazer.reg.RidgeRegThreaded = ridgeRegThreaded.RidgeRegThreaded;
webgazer.reg.RidgeRegXpln = RidgeRegXpln;
webgazer.util = util;
webgazer.params = params;

Expand Down Expand Up @@ -57,7 +59,10 @@ var eventTypes = ['click', 'move'];
//movelistener timeout clock parameters
var moveClock = performance.now();
//currently used tracker and regression models, defaults to clmtrackr and linear regression
/* xpln.ai 2023-11-19: Disable default TFFaceMesh tracker, because we use our own faceTracker!
var curTracker = new webgazer.tracker.TFFaceMesh();
*/
var curTracker = null; // xpln.ai 2023-11-19
var regs = [new webgazer.reg.RidgeReg()];
// var blinkDetector = new webgazer.BlinkDetector();

Expand Down
87 changes: 87 additions & 0 deletions src/ridgeRegXpln.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import util from './util.mjs';
import util_regression from './util_regression.mjs';

/**
* Constructor of RidgeRegXpln object,
* this object allow to perform ridge regression
* @constructor
*/
const RidgeRegXpln = function() {
this.init();
};

/**
* Initialize new arrays and initialize Kalman filter.
*/
RidgeRegXpln.prototype.init = util_regression.InitRegression

/**
* Add given data from features
* @param {Array} features - features where extract data to add
* @param {Object} screenPos - The current screen point
* @param {Object} type - The type of performed action
*/
RidgeRegXpln.prototype.addData = function(features, screenPos, type) {
if (!features) return;
if (type === 'click') {
this.screenXClicksArray.push([screenPos[0]]);
this.screenYClicksArray.push([screenPos[1]]);
this.eyeFeaturesClicks.push(features);
delete this.xCoef;
delete this.yCoef;
} else if (type === 'move') {
throw new Error('Not implemented!!!');
}
};

/**
* Try to predict coordinates from pupil data
* after apply linear regression on data set
* @param {Array} features - The current user features features
* @returns {Object}
*/
RidgeRegXpln.prototype.predict = function(features) {
if (!features || this.eyeFeaturesClicks.length === 0) {
return null;
}

if (!this.xCoef || !this.yCoef) {
var screenXArray = this.screenXClicksArray.data;
var screenYArray = this.screenYClicksArray.data;
var eyeFeatures = this.eyeFeaturesClicks.data;
this.xCoef = util_regression.ridge(screenXArray, eyeFeatures, this.ridgeParameter);
this.yCoef = util_regression.ridge(screenYArray, eyeFeatures, this.ridgeParameter);
}

var predictedX = 0, predictedY = 0, cx = this.xCoef, cy = this.yCoef;
for(var i=0; i< features.length; i++) {
var f = features[i];
predictedX += f * cx[i];
predictedY += f * cy[i];
}

return {
x: Math.floor(predictedX),
y: Math.floor(predictedY)
};
};

RidgeRegXpln.prototype.setData = function() {
throw new Error('Not implemented!!!');
};

/**
* Return the data
* @returns {Array.<Object>|*}
*/
RidgeRegXpln.prototype.getData = function() {
throw new Error('Not implemented!!!');
};

/**
* The RidgeRegXpln object name
* @type {string}
*/
RidgeRegXpln.prototype.name = 'ridgeXpln';

export default RidgeRegXpln;
22 changes: 20 additions & 2 deletions src/util.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ util.Eye = function(patch, imagex, imagey, width, height) {
this.height = height;
};

// xpln.ai 2024-02-26: normalize pixel values between 0 and 1
util.normalize = function(arr, digits) {
var min = Infinity, max = -Infinity, precision = Math.pow(10, digits);
for (var i=0, imax=arr.length; i<imax; i++) {
if (min > arr[i]) min = arr[i];
if (max < arr[i]) max = arr[i];
}
var range = max - min;
if (!range) return;
for (var i=0, imax=arr.length; i<imax; i++) {
arr[i] = Math.round(precision * (arr[i] - min) / range) / precision;
}
};

/**
* Compute eyes size as gray histogram
* @param {Object} eyes - The eyes where looking for gray histogram
Expand All @@ -35,17 +49,21 @@ util.getEyeFeats = function(eyes) {
let gray = this.grayscale(resized.data, resized.width, resized.height);
let hist = [];
this.equalizeHistogram(gray, 5, hist);
// xpln.ai 2024-02-26: normalize pixel values between 0 and 1
if (eyes.normalize) this.normalize(hist, 3);
return hist;
};

// xpln.ai 2023-11-27: simply override data for ridge regression
if (eyes.ridgeRegData) return eyes.ridgeRegData;
if (webgazer.params.trackEye == 'left') {
return process(eyes.left);
}
else if (webgazer.params.trackEye == 'right') {
return process(eyes.right);
}
else {
return [].concat(process(eyes.left), process(eyes.right));
// xpln.ai 2024-02-09: add extra data for ridge regression
return [].concat(process(eyes.left), process(eyes.right), eyes.ridgeRegExtra);
}
}

Expand Down
4 changes: 4 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,14 @@ const varConfig = {
events: {
onEnd: {
copy: [
/* xpln.ai 2023-11-19: Disable useless copy to ./www/
{ source: './dist/webgazer.js', destination: './www/' },
{ source: './dist/webgazer.js.map', destination: './www/' },
{ source: './dist/webgazer.js', destination: './www/data/src/' },
{ source: './dist/webgazer.js.map', destination: './www/data/src/' },
*/
// xpln.ai 2023-11-19: Instead we copy to our own chrome extension
{ source: './dist/webgazer.js', destination: '../xpln.ai/scripts_crea/chrome_extension/ext/webgazer/webgazer.js', options: { overwrite: true } },
],
},
},
Expand Down