remote-calibrator 0.2.1 → 0.2.2-beta.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +16 -0
- package/README.md +2 -0
- package/homepage/example.js +11 -13
- package/lib/RemoteCalibrator.min.js +1 -1
- package/lib/RemoteCalibrator.min.js.LICENSE.txt +1 -1
- package/lib/RemoteCalibrator.min.js.map +1 -1
- package/package.json +8 -8
- package/src/WebGazer4RC/.gitattributes +10 -0
- package/src/WebGazer4RC/LICENSE.md +15 -0
- package/src/WebGazer4RC/README.md +142 -0
- package/src/WebGazer4RC/gnu-lgpl-v3.0.md +163 -0
- package/src/WebGazer4RC/gplv3.md +636 -0
- package/src/WebGazer4RC/package-lock.json +1133 -0
- package/src/WebGazer4RC/package.json +28 -0
- package/src/WebGazer4RC/src/dom_util.mjs +27 -0
- package/src/WebGazer4RC/src/facemesh.mjs +150 -0
- package/src/WebGazer4RC/src/index.mjs +1213 -0
- package/src/WebGazer4RC/src/mat.mjs +301 -0
- package/src/WebGazer4RC/src/params.mjs +29 -0
- package/src/WebGazer4RC/src/pupil.mjs +109 -0
- package/src/WebGazer4RC/src/ridgeReg.mjs +104 -0
- package/src/WebGazer4RC/src/ridgeRegThreaded.mjs +161 -0
- package/src/WebGazer4RC/src/ridgeWeightedReg.mjs +125 -0
- package/src/WebGazer4RC/src/ridgeWorker.mjs +135 -0
- package/src/WebGazer4RC/src/util.mjs +348 -0
- package/src/WebGazer4RC/src/util_regression.mjs +240 -0
- package/src/WebGazer4RC/src/worker_scripts/mat.js +306 -0
- package/src/WebGazer4RC/src/worker_scripts/util.js +398 -0
- package/src/WebGazer4RC/test/regression_test.js +182 -0
- package/src/WebGazer4RC/test/run_tests_and_server.sh +24 -0
- package/src/WebGazer4RC/test/util_test.js +60 -0
- package/src/WebGazer4RC/test/webgazerExtract_test.js +40 -0
- package/src/WebGazer4RC/test/webgazer_test.js +160 -0
- package/src/WebGazer4RC/test/www_page_test.js +41 -0
- package/src/components/onCanvas.js +1 -2
- package/src/core.js +18 -0
- package/src/css/distance.scss +1 -0
- package/src/distance/distance.js +4 -1
- package/src/distance/distanceTrack.js +2 -2
- package/src/panel/panel.js +14 -5
- package/src/text.json +4 -2
@@ -0,0 +1,398 @@
|
|
1
|
+
'use strict';
|
2
|
+
(function() {
|
3
|
+
|
4
|
+
self.webgazer = self.webgazer || {};
|
5
|
+
self.webgazer.util = self.webgazer.util || {};
|
6
|
+
self.webgazer.mat = self.webgazer.mat || {};
|
7
|
+
|
8
|
+
/**
|
9
|
+
* Eye class, represents an eye patch detected in the video stream
|
10
|
+
* @param {ImageData} patch - the image data corresponding to an eye
|
11
|
+
* @param {Number} imagex - x-axis offset from the top-left corner of the video canvas
|
12
|
+
* @param {Number} imagey - y-axis offset from the top-left corner of the video canvas
|
13
|
+
* @param {Number} width - width of the eye patch
|
14
|
+
* @param {Number} height - height of the eye patch
|
15
|
+
*/
|
16
|
+
self.webgazer.util.Eye = function(patch, imagex, imagey, width, height) {
|
17
|
+
this.patch = patch;
|
18
|
+
this.imagex = imagex;
|
19
|
+
this.imagey = imagey;
|
20
|
+
this.width = width;
|
21
|
+
this.height = height;
|
22
|
+
};
|
23
|
+
|
24
|
+
|
25
|
+
//Data Window class
|
26
|
+
//operates like an array but 'wraps' data around to keep the array at a fixed windowSize
|
27
|
+
/**
|
28
|
+
* DataWindow class - Operates like an array, but 'wraps' data around to keep the array at a fixed windowSize
|
29
|
+
* @param {Number} windowSize - defines the maximum size of the window
|
30
|
+
* @param {Array} data - optional data to seed the DataWindow with
|
31
|
+
**/
|
32
|
+
self.webgazer.util.DataWindow = function(windowSize, data) {
|
33
|
+
this.data = [];
|
34
|
+
this.windowSize = windowSize;
|
35
|
+
this.index = 0;
|
36
|
+
this.length = 0;
|
37
|
+
if(data){
|
38
|
+
this.data = data.slice(data.length-windowSize,data.length);
|
39
|
+
this.length = this.data.length;
|
40
|
+
}
|
41
|
+
};
|
42
|
+
|
43
|
+
/**
|
44
|
+
* [push description]
|
45
|
+
* @param {*} entry - item to be inserted. It either grows the DataWindow or replaces the oldest item
|
46
|
+
* @return {DataWindow} this
|
47
|
+
*/
|
48
|
+
self.webgazer.util.DataWindow.prototype.push = function(entry) {
|
49
|
+
if (this.data.length < this.windowSize) {
|
50
|
+
this.data.push(entry);
|
51
|
+
this.length = this.data.length;
|
52
|
+
return this;
|
53
|
+
}
|
54
|
+
|
55
|
+
//replace oldest entry by wrapping around the DataWindow
|
56
|
+
this.data[this.index] = entry;
|
57
|
+
this.index = (this.index + 1) % this.windowSize;
|
58
|
+
return this;
|
59
|
+
};
|
60
|
+
|
61
|
+
/**
|
62
|
+
* Get the element at the ind position by wrapping around the DataWindow
|
63
|
+
* @param {Number} ind index of desired entry
|
64
|
+
* @return {*}
|
65
|
+
*/
|
66
|
+
self.webgazer.util.DataWindow.prototype.get = function(ind) {
|
67
|
+
return this.data[this.getTrueIndex(ind)];
|
68
|
+
};
|
69
|
+
|
70
|
+
/**
|
71
|
+
* Gets the true this.data array index given an index for a desired element
|
72
|
+
* @param {Number} ind - index of desired entry
|
73
|
+
* @return {Number} index of desired entry in this.data
|
74
|
+
*/
|
75
|
+
self.webgazer.util.DataWindow.prototype.getTrueIndex = function(ind) {
|
76
|
+
if (this.data.length < this.windowSize) {
|
77
|
+
return ind;
|
78
|
+
} else {
|
79
|
+
//wrap around ind so that we can traverse from oldest to newest
|
80
|
+
return (ind + this.index) % this.windowSize;
|
81
|
+
}
|
82
|
+
};
|
83
|
+
|
84
|
+
/**
|
85
|
+
* Append all the contents of data
|
86
|
+
* @param {Array} data - to be inserted
|
87
|
+
*/
|
88
|
+
self.webgazer.util.DataWindow.prototype.addAll = function(data) {
|
89
|
+
for (var i = 0; i < data.length; i++) {
|
90
|
+
this.push(data[i]);
|
91
|
+
}
|
92
|
+
};
|
93
|
+
|
94
|
+
|
95
|
+
//Helper functions
|
96
|
+
/**
|
97
|
+
* Grayscales an image patch. Can be used for the whole canvas, detected face, detected eye, etc.
|
98
|
+
*
|
99
|
+
* Code from tracking.js by Eduardo Lundgren, et al.
|
100
|
+
* https://github.com/eduardolundgren/tracking.js/blob/master/src/tracking.js
|
101
|
+
*
|
102
|
+
* Software License Agreement (BSD License) Copyright (c) 2014, Eduardo A. Lundgren Melo. All rights reserved.
|
103
|
+
* Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
104
|
+
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
105
|
+
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
106
|
+
* The name of Eduardo A. Lundgren Melo may not be used to endorse or promote products derived from this software without specific prior written permission of Eduardo A. Lundgren Melo.
|
107
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
108
|
+
* IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
109
|
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
110
|
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
111
|
+
*
|
112
|
+
* @param {Array} pixels - image data to be grayscaled
|
113
|
+
* @param {Number} width - width of image data to be grayscaled
|
114
|
+
* @param {Number} height - height of image data to be grayscaled
|
115
|
+
* @return {Array} grayscaledImage
|
116
|
+
*/
|
117
|
+
self.webgazer.util.grayscale = function(pixels, width, height){
|
118
|
+
var gray = new Uint8ClampedArray(pixels.length >> 2);
|
119
|
+
var p = 0;
|
120
|
+
var w = 0;
|
121
|
+
for (var i = 0; i < height; i++) {
|
122
|
+
for (var j = 0; j < width; j++) {
|
123
|
+
var value = pixels[w] * 0.299 + pixels[w + 1] * 0.587 + pixels[w + 2] * 0.114;
|
124
|
+
gray[p++] = value;
|
125
|
+
|
126
|
+
w += 4;
|
127
|
+
}
|
128
|
+
}
|
129
|
+
return gray;
|
130
|
+
};
|
131
|
+
|
132
|
+
/**
|
133
|
+
* Increase contrast of an image.
|
134
|
+
*
|
135
|
+
* Code from Martin Tschirsich, Copyright (c) 2012.
|
136
|
+
* https://github.com/mtschirs/js-objectdetect/blob/gh-pages/js/objectdetect.js
|
137
|
+
*
|
138
|
+
* @param {Array} src - grayscale integer array
|
139
|
+
* @param {Number} step - sampling rate, control performance
|
140
|
+
* @param {Array} dst - array to hold the resulting image
|
141
|
+
*/
|
142
|
+
self.webgazer.util.equalizeHistogram = function(src, step, dst) {
|
143
|
+
var srcLength = src.length;
|
144
|
+
if (!dst) dst = src;
|
145
|
+
if (!step) step = 5;
|
146
|
+
|
147
|
+
// Compute histogram and histogram sum:
|
148
|
+
var hist = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
149
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
150
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
151
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
152
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
153
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
154
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
155
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
156
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
157
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
158
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
159
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
160
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
161
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
162
|
+
0, 0, 0, 0];
|
163
|
+
|
164
|
+
for (var i = 0; i < srcLength; i += step) {
|
165
|
+
++hist[src[i]];
|
166
|
+
}
|
167
|
+
|
168
|
+
// Compute integral histogram:
|
169
|
+
var norm = 255 * step / srcLength,
|
170
|
+
prev = 0;
|
171
|
+
for (var i = 0; i < 256; ++i) {
|
172
|
+
var h = hist[i];
|
173
|
+
prev = h += prev;
|
174
|
+
hist[i] = h * norm; // For non-integer src: ~~(h * norm + 0.5);
|
175
|
+
}
|
176
|
+
|
177
|
+
// Equalize image:
|
178
|
+
for (var i = 0; i < srcLength; ++i) {
|
179
|
+
dst[i] = hist[src[i]];
|
180
|
+
}
|
181
|
+
return dst;
|
182
|
+
};
|
183
|
+
|
184
|
+
self.webgazer.util.threshold = function(data, threshold) {
|
185
|
+
for (let i = 0; i < data.length; i++) {
|
186
|
+
data[i] = (data[i] > threshold) ? 255 : 0;
|
187
|
+
}
|
188
|
+
return data;
|
189
|
+
};
|
190
|
+
|
191
|
+
self.webgazer.util.correlation = function(data1, data2) {
|
192
|
+
const length = Math.min(data1.length, data2.length);
|
193
|
+
let count = 0;
|
194
|
+
for (let i = 0; i < length; i++) {
|
195
|
+
if (data1[i] === data2[i]) {
|
196
|
+
count++;
|
197
|
+
}
|
198
|
+
}
|
199
|
+
return count / Math.max(data1.length, data2.length);
|
200
|
+
};
|
201
|
+
|
202
|
+
/**
|
203
|
+
* Gets an Eye object and resizes it to the desired resolution
|
204
|
+
* @param {webgazer.util.Eye} eye - patch to be resized
|
205
|
+
* @param {Number} resizeWidth - desired width
|
206
|
+
* @param {Number} resizeHeight - desired height
|
207
|
+
* @return {webgazer.util.Eye} resized eye patch
|
208
|
+
*/
|
209
|
+
self.webgazer.util.resizeEye = function(eye, resizeWidth, resizeHeight) {
|
210
|
+
|
211
|
+
var canvas = document.createElement('canvas');
|
212
|
+
canvas.width = eye.width;
|
213
|
+
canvas.height = eye.height;
|
214
|
+
|
215
|
+
canvas.getContext('2d').putImageData(eye.patch,0,0);
|
216
|
+
|
217
|
+
var tempCanvas = document.createElement('canvas');
|
218
|
+
|
219
|
+
tempCanvas.width = resizeWidth;
|
220
|
+
tempCanvas.height = resizeHeight;
|
221
|
+
|
222
|
+
// save the canvas into temp canvas
|
223
|
+
tempCanvas.getContext('2d').drawImage(canvas, 0, 0, canvas.width, canvas.height, 0, 0, resizeWidth, resizeHeight);
|
224
|
+
|
225
|
+
return tempCanvas.getContext('2d').getImageData(0, 0, resizeWidth, resizeHeight);
|
226
|
+
};
|
227
|
+
|
228
|
+
/**
|
229
|
+
* Checks if the prediction is within the boundaries of the viewport and constrains it
|
230
|
+
* @param {Array} prediction [x,y] - predicted gaze coordinates
|
231
|
+
* @return {Array} constrained coordinates
|
232
|
+
*/
|
233
|
+
self.webgazer.util.bound = function(prediction){
|
234
|
+
if(prediction.x < 0)
|
235
|
+
prediction.x = 0;
|
236
|
+
if(prediction.y < 0)
|
237
|
+
prediction.y = 0;
|
238
|
+
var w = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
|
239
|
+
var h = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
|
240
|
+
if(prediction.x > w){
|
241
|
+
prediction.x = w;
|
242
|
+
}
|
243
|
+
|
244
|
+
if(prediction.y > h)
|
245
|
+
{
|
246
|
+
prediction.y = h;
|
247
|
+
}
|
248
|
+
return prediction;
|
249
|
+
};
|
250
|
+
|
251
|
+
/**
|
252
|
+
* Write statistics in debug paragraph panel
|
253
|
+
* @param {HTMLElement} para - The <p> tag where write data
|
254
|
+
* @param {Object} stats - The stats data to output
|
255
|
+
*/
|
256
|
+
function debugBoxWrite(para, stats) {
|
257
|
+
var str = '';
|
258
|
+
for (var key in stats) {
|
259
|
+
str += key + ': ' + stats[key] + '\n';
|
260
|
+
}
|
261
|
+
para.innerText = str;
|
262
|
+
}
|
263
|
+
|
264
|
+
/**
|
265
|
+
* Constructor of DebugBox object,
|
266
|
+
* it insert an paragraph inside a div to the body, in view to display debug data
|
267
|
+
* @param {Number} interval - The log interval
|
268
|
+
* @constructor
|
269
|
+
*/
|
270
|
+
self.webgazer.util.DebugBox = function(interval) {
|
271
|
+
this.para = document.createElement('p');
|
272
|
+
this.div = document.createElement('div');
|
273
|
+
this.div.appendChild(this.para);
|
274
|
+
document.body.appendChild(this.div);
|
275
|
+
|
276
|
+
this.buttons = {};
|
277
|
+
this.canvas = {};
|
278
|
+
this.stats = {};
|
279
|
+
var updateInterval = interval || 300;
|
280
|
+
(function(localThis) {
|
281
|
+
setInterval(function() {
|
282
|
+
debugBoxWrite(localThis.para, localThis.stats);
|
283
|
+
}, updateInterval);
|
284
|
+
}(this));
|
285
|
+
};
|
286
|
+
|
287
|
+
/**
|
288
|
+
* Add stat data for log
|
289
|
+
* @param {String} key - The data key
|
290
|
+
* @param {*} value - The value
|
291
|
+
*/
|
292
|
+
self.webgazer.util.DebugBox.prototype.set = function(key, value) {
|
293
|
+
this.stats[key] = value;
|
294
|
+
};
|
295
|
+
|
296
|
+
/**
|
297
|
+
* Initialize stats in case where key does not exist, else
|
298
|
+
* increment value for key
|
299
|
+
* @param {String} key - The key to process
|
300
|
+
* @param {Number} incBy - Value to increment for given key (default: 1)
|
301
|
+
* @param {Number} init - Initial value in case where key does not exist (default: 0)
|
302
|
+
*/
|
303
|
+
self.webgazer.util.DebugBox.prototype.inc = function(key, incBy, init) {
|
304
|
+
if (!this.stats[key]) {
|
305
|
+
this.stats[key] = init || 0;
|
306
|
+
}
|
307
|
+
this.stats[key] += incBy || 1;
|
308
|
+
};
|
309
|
+
|
310
|
+
/**
|
311
|
+
* Create a button and register the given function to the button click event
|
312
|
+
* @param {String} name - The button name to link
|
313
|
+
* @param {Function} func - The onClick callback
|
314
|
+
*/
|
315
|
+
self.webgazer.util.DebugBox.prototype.addButton = function(name, func) {
|
316
|
+
if (!this.buttons[name]) {
|
317
|
+
this.buttons[name] = document.createElement('button');
|
318
|
+
this.div.appendChild(this.buttons[name]);
|
319
|
+
}
|
320
|
+
var button = this.buttons[name];
|
321
|
+
this.buttons[name] = button;
|
322
|
+
button.addEventListener('click', func);
|
323
|
+
button.innerText = name;
|
324
|
+
};
|
325
|
+
|
326
|
+
/**
|
327
|
+
* Search for a canvas elemenet with name, or create on if not exist.
|
328
|
+
* Then send the canvas element as callback parameter.
|
329
|
+
* @param {String} name - The canvas name to send/create
|
330
|
+
* @param {Function} func - The callback function where send canvas
|
331
|
+
*/
|
332
|
+
self.webgazer.util.DebugBox.prototype.show = function(name, func) {
|
333
|
+
if (!this.canvas[name]) {
|
334
|
+
this.canvas[name] = document.createElement('canvas');
|
335
|
+
this.div.appendChild(this.canvas[name]);
|
336
|
+
}
|
337
|
+
var canvas = this.canvas[name];
|
338
|
+
canvas.getContext('2d').clearRect(0,0, canvas.width, canvas.height);
|
339
|
+
func(canvas);
|
340
|
+
};
|
341
|
+
|
342
|
+
/**
|
343
|
+
* Kalman Filter constructor
|
344
|
+
* Kalman filters work by reducing the amount of noise in a models.
|
345
|
+
* https://blog.cordiner.net/2011/05/03/object-tracking-using-a-kalman-filter-matlab/
|
346
|
+
*
|
347
|
+
* @param {Array.<Array.<Number>>} F - transition matrix
|
348
|
+
* @param {Array.<Array.<Number>>} Q - process noise matrix
|
349
|
+
* @param {Array.<Array.<Number>>} H - maps between measurement vector and noise matrix
|
350
|
+
* @param {Array.<Array.<Number>>} R - defines measurement error of the device
|
351
|
+
* @param {Array} P_initial - the initial state
|
352
|
+
* @param {Array} X_initial - the initial state of the device
|
353
|
+
*/
|
354
|
+
self.webgazer.util.KalmanFilter = function(F, H, Q, R, P_initial, X_initial) {
|
355
|
+
this.F = F; // State transition matrix
|
356
|
+
this.Q = Q; // Process noise matrix
|
357
|
+
this.H = H; // Transformation matrix
|
358
|
+
this.R = R; // Measurement Noise
|
359
|
+
this.P = P_initial; //Initial covariance matrix
|
360
|
+
this.X = X_initial; //Initial guess of measurement
|
361
|
+
};
|
362
|
+
|
363
|
+
/**
|
364
|
+
* Get Kalman next filtered value and update the internal state
|
365
|
+
* @param {Array} z - the new measurement
|
366
|
+
* @return {Array}
|
367
|
+
*/
|
368
|
+
self.webgazer.util.KalmanFilter.prototype.update = function(z) {
|
369
|
+
|
370
|
+
// Here, we define all the different matrix operations we will need
|
371
|
+
var add = numeric.add, sub = numeric.sub, inv = numeric.inv, identity = numeric.identity;
|
372
|
+
var mult = webgazer.mat.mult, transpose = webgazer.mat.transpose;
|
373
|
+
//TODO cache variables like the transpose of H
|
374
|
+
|
375
|
+
// prediction: X = F * X | P = F * P * F' + Q
|
376
|
+
var X_p = mult(this.F, this.X); //Update state vector
|
377
|
+
var P_p = add(mult(mult(this.F,this.P), transpose(this.F)), this.Q); //Predicted covaraince
|
378
|
+
|
379
|
+
//Calculate the update values
|
380
|
+
var y = sub(z, mult(this.H, X_p)); // This is the measurement error (between what we expect and the actual value)
|
381
|
+
var S = add(mult(mult(this.H, P_p), transpose(this.H)), this.R); //This is the residual covariance (the error in the covariance)
|
382
|
+
|
383
|
+
// kalman multiplier: K = P * H' * (H * P * H' + R)^-1
|
384
|
+
var K = mult(P_p, mult(transpose(this.H), inv(S))); //This is the Optimal Kalman Gain
|
385
|
+
|
386
|
+
//We need to change Y into it's column vector form
|
387
|
+
for(var i = 0; i < y.length; i++){
|
388
|
+
y[i] = [y[i]];
|
389
|
+
}
|
390
|
+
|
391
|
+
//Now we correct the internal values of the model
|
392
|
+
// correction: X = X + K * (m - H * X) | P = (I - K * H) * P
|
393
|
+
this.X = add(X_p, mult(K, y));
|
394
|
+
this.P = mult(sub(identity(K.length), mult(K,this.H)), P_p);
|
395
|
+
return transpose(mult(this.H, this.X))[0]; //Transforms the predicted state back into it's measurement form
|
396
|
+
};
|
397
|
+
|
398
|
+
}());
|
@@ -0,0 +1,182 @@
|
|
1
|
+
const { assert } = require('chai');
|
2
|
+
|
3
|
+
describe('regression functions', async()=> {
|
4
|
+
describe('top level functions', async()=> {
|
5
|
+
it('default regression should be ridge and it should have default properties', async() =>{
|
6
|
+
const regression_set = await page.evaluate(async() => {
|
7
|
+
return await webgazer.getRegression()
|
8
|
+
})
|
9
|
+
const regression_name = await page.evaluate(async() => {
|
10
|
+
return await webgazer.getRegression()[0].name
|
11
|
+
})
|
12
|
+
assert.equal(regression_name,"ridge")
|
13
|
+
assert.isNotNull(regression_set[0].dataClicks)
|
14
|
+
assert.isNotNull(regression_set[0].dataTrail)
|
15
|
+
assert.isNotNull(regression_set[0].eyeFeaturesClicks)
|
16
|
+
assert.isNotNull(regression_set[0].eyeFeaturesTrail)
|
17
|
+
assert.isNotNull(regression_set[0].kalman)
|
18
|
+
assert.isNotNull(regression_set[0].ridgeParameter)
|
19
|
+
assert.isNotNull(regression_set[0].screenXClicksArray)
|
20
|
+
assert.isNotNull(regression_set[0].screenYClicksArray)
|
21
|
+
assert.isNotNull(regression_set[0].screenXTrailArray)
|
22
|
+
assert.isNotNull(regression_set[0].screenYTrailArray)
|
23
|
+
assert.isNotNull(regression_set[0].trailDataWindow)
|
24
|
+
assert.isNotNull(regression_set[0].trailTime)
|
25
|
+
assert.isNotNull(regression_set[0].trailTimes)
|
26
|
+
})
|
27
|
+
|
28
|
+
it('mouse clicks and moves should be stored in regs', async()=>{
|
29
|
+
await page.mouse.click(500,600)
|
30
|
+
let regsClicksArray = await page.evaluate(async()=>{
|
31
|
+
//these indices will change if other tests produce clicks
|
32
|
+
return {x:await webgazer.getRegression()[0].screenXClicksArray.data[1][0],
|
33
|
+
y:await webgazer.getRegression()[0].screenYClicksArray.data[1][0]}
|
34
|
+
})
|
35
|
+
assert.equal(regsClicksArray.x,500)
|
36
|
+
assert.equal(regsClicksArray.y,600)
|
37
|
+
|
38
|
+
await page.mouse.move(50, 60);
|
39
|
+
let regsTrailArray = await page.evaluate(async()=>{
|
40
|
+
return {x:await webgazer.getRegression()[0].screenXTrailArray.data[0],
|
41
|
+
y:await webgazer.getRegression()[0].screenYTrailArray.data[0]}
|
42
|
+
})
|
43
|
+
assert.equal(regsTrailArray.x[0],50)
|
44
|
+
assert.equal(regsTrailArray.y[0],60)
|
45
|
+
})
|
46
|
+
it('should be able to store points', async()=>{
|
47
|
+
const points = await page.evaluate(async()=>{
|
48
|
+
await webgazer.storePoints(100, 200, 0)
|
49
|
+
return await webgazer.getStoredPoints()
|
50
|
+
})
|
51
|
+
assert.equal(points[0][0],100)
|
52
|
+
assert.equal(points[1][0],200)
|
53
|
+
})
|
54
|
+
it('should return regression data', async()=> {
|
55
|
+
await page.evaluate(async() => {
|
56
|
+
document.getElementsByClassName('Calibration')[0].click()
|
57
|
+
|
58
|
+
})
|
59
|
+
let regs = await page.evaluate(async()=>{
|
60
|
+
return await webgazer.getRegression()
|
61
|
+
})
|
62
|
+
assert.isNotNull(regs)
|
63
|
+
})
|
64
|
+
it('should make predictions', async()=>{
|
65
|
+
const prediction = await page.evaluate(async() => {
|
66
|
+
return await webgazer.getCurrentPrediction()
|
67
|
+
})
|
68
|
+
assert.isNotNull(prediction)
|
69
|
+
})
|
70
|
+
|
71
|
+
it('should be able to add a new regression', async()=>{
|
72
|
+
const new_regression = await page.evaluate(async() => {
|
73
|
+
webgazer.addRegression("weightedRidge")
|
74
|
+
return await webgazer.getRegression()[1]
|
75
|
+
})
|
76
|
+
assert.isNotNull(new_regression)
|
77
|
+
assert.isNotNull(new_regression.dataClicks)
|
78
|
+
assert.isNotNull(new_regression.dataTrail)
|
79
|
+
assert.isNotNull(new_regression.eyeFeaturesClicks)
|
80
|
+
assert.isNotNull(new_regression.eyeFeaturesTrail)
|
81
|
+
assert.isNotNull(new_regression.kalman)
|
82
|
+
assert.isNotNull(new_regression.ridgeParameter)
|
83
|
+
assert.isNotNull(new_regression.screenXClicksArray)
|
84
|
+
assert.isNotNull(new_regression.screenYClicksArray)
|
85
|
+
assert.isNotNull(new_regression.screenXTrailArray)
|
86
|
+
assert.isNotNull(new_regression.screenYTrailArray)
|
87
|
+
assert.isNotNull(new_regression.trailDataWindow)
|
88
|
+
assert.isNotNull(new_regression.trailTime)
|
89
|
+
assert.isNotNull(new_regression.trailTimes)
|
90
|
+
})
|
91
|
+
})
|
92
|
+
describe("regression ridge predictions", async()=>{
|
93
|
+
it('should return null when prediction is called with no eyesObjects', async()=>{
|
94
|
+
const no_eyes_prediction = await page.evaluate(async() => {
|
95
|
+
return await webgazer.getRegression()[0].predict()
|
96
|
+
})
|
97
|
+
assert.isNull(no_eyes_prediction)
|
98
|
+
})
|
99
|
+
it('should return a prediction when eyesObject is valid', async()=>{
|
100
|
+
const eyes_prediction = await page.evaluate(async() => {
|
101
|
+
const videoElementCanvas = document.getElementById('webgazerVideoCanvas')
|
102
|
+
const eyeFeatures = await webgazer.getTracker().getEyePatches(videoElementCanvas,videoElementCanvas.width,videoElementCanvas.height)
|
103
|
+
return await webgazer.getRegression()[0].predict(eyeFeatures)
|
104
|
+
})
|
105
|
+
assert.isNotNull(eyes_prediction)
|
106
|
+
})
|
107
|
+
it('Kalman filter should exist and have properties', async()=>{
|
108
|
+
const kalman_applied = await page.evaluate(async() => {
|
109
|
+
return webgazer.applyKalmanFilter()
|
110
|
+
})
|
111
|
+
assert.isNotNull(kalman_applied)
|
112
|
+
const kalman_filter = await page.evaluate(async() => {
|
113
|
+
return webgazer.getRegression()[0].kalman
|
114
|
+
})
|
115
|
+
assert.isNotNull(kalman_filter.F)
|
116
|
+
assert.isNotNull(kalman_filter.H)
|
117
|
+
assert.isNotNull(kalman_filter.P)
|
118
|
+
assert.isNotNull(kalman_filter.Q)
|
119
|
+
assert.isNotNull(kalman_filter.R)
|
120
|
+
assert.isNotNull(kalman_filter.X)
|
121
|
+
})
|
122
|
+
it('Kalman filter should be updateable', async()=>{
|
123
|
+
const kalman_filter_upgdate = await page.evaluate(async() => {
|
124
|
+
return webgazer.getRegression()[0].kalman.update([500,500])
|
125
|
+
})
|
126
|
+
assert.isNotNull(kalman_filter_upgdate)
|
127
|
+
|
128
|
+
})
|
129
|
+
})
|
130
|
+
describe("regression ridgeWeighted predictions", async()=>{
|
131
|
+
it('should return null when prediction is called with no eyesObjects', async()=>{
|
132
|
+
const no_eyes_prediction = await page.evaluate(async() => {
|
133
|
+
return await webgazer.getRegression()[1].predict()
|
134
|
+
})
|
135
|
+
assert.isNull(no_eyes_prediction)
|
136
|
+
})
|
137
|
+
it('should return a prediction when eyesObject is valid', async()=>{
|
138
|
+
const eyes_prediction = await page.evaluate(async() => {
|
139
|
+
const videoElementCanvas = document.getElementById('webgazerVideoCanvas')
|
140
|
+
const eyeFeatures = await webgazer.getTracker().getEyePatches(videoElementCanvas,videoElementCanvas.width,videoElementCanvas.height)
|
141
|
+
return await webgazer.getRegression()[1].predict(eyeFeatures)
|
142
|
+
})
|
143
|
+
assert.isNotNull(eyes_prediction)
|
144
|
+
})
|
145
|
+
it('Kalman filter should exist and have properties', async()=>{
|
146
|
+
const kalman_applied = await page.evaluate(async() => {
|
147
|
+
return webgazer.applyKalmanFilter()
|
148
|
+
})
|
149
|
+
assert.isNotNull(kalman_applied)
|
150
|
+
const kalman_filter = await page.evaluate(async() => {
|
151
|
+
return webgazer.getRegression()[1].kalman
|
152
|
+
})
|
153
|
+
assert.isNotNull(kalman_filter.F)
|
154
|
+
assert.isNotNull(kalman_filter.H)
|
155
|
+
assert.isNotNull(kalman_filter.P)
|
156
|
+
assert.isNotNull(kalman_filter.Q)
|
157
|
+
assert.isNotNull(kalman_filter.R)
|
158
|
+
assert.isNotNull(kalman_filter.X)
|
159
|
+
})
|
160
|
+
it('Kalman filter should be updateable', async()=>{
|
161
|
+
const kalman_filter_upgdate = await page.evaluate(async() => {
|
162
|
+
return webgazer.getRegression()[1].kalman.update([500,500])
|
163
|
+
})
|
164
|
+
assert.isNotNull(kalman_filter_upgdate)
|
165
|
+
})
|
166
|
+
it('should be able to grayscale an image', async() =>{
|
167
|
+
const grayscale = await page.evaluate(async() => {
|
168
|
+
const videoElementCanvas = document.getElementById('webgazerVideoCanvas')
|
169
|
+
const eyeFeatures = await webgazer.getTracker().getEyePatches(videoElementCanvas,videoElementCanvas.width,videoElementCanvas.height)
|
170
|
+
return await webgazer.util.grayscale(eyeFeatures.left)
|
171
|
+
})
|
172
|
+
assert.isNotNull(grayscale)
|
173
|
+
|
174
|
+
it('should be able to equalize a grayscaled image', async() =>{
|
175
|
+
const equalizeHistogram = await page.evaluate(async() => {
|
176
|
+
await webgazer.util.equalizeHistogram(grayscale,5,[])
|
177
|
+
})
|
178
|
+
assert.isNotNull(equalizeHistogram)
|
179
|
+
})
|
180
|
+
})
|
181
|
+
})
|
182
|
+
})
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
if ! [ -f www/data/src/P_01/dot.y4m ] ; then
|
3
|
+
echo "Creating .y4m file for video input"
|
4
|
+
ffmpeg -hide_banner -loglevel panic -i www/data/src/P_01/1491423217564_2_-study-dot_test_instructions.webm -pix_fmt yuv420p dot.y4m > /dev/null
|
5
|
+
sed -i.bak '0,/C420mpeg2/s//C420/' dot.y4m
|
6
|
+
mv dot.y4m www/data/src/P_01/
|
7
|
+
rm dot.y4m.bak
|
8
|
+
fi
|
9
|
+
if ! lsof -i:8000 > /dev/null; then
|
10
|
+
cd www/data/src
|
11
|
+
python3 webgazerExtractServer.py > /dev/null &
|
12
|
+
cd ../../..
|
13
|
+
fi
|
14
|
+
if ! lsof -i:3000 > /dev/null; then
|
15
|
+
cd www/
|
16
|
+
browser-sync start --server --no-open > /dev/null &
|
17
|
+
cd ..
|
18
|
+
fi
|
19
|
+
echo "starting tests..."
|
20
|
+
npx mocha test --recursive --no-timeouts
|
21
|
+
echo "finishing tests, killing servers..."
|
22
|
+
|
23
|
+
kill $(lsof -t -i:3000)
|
24
|
+
kill $(lsof -t -i:8000)
|
@@ -0,0 +1,60 @@
|
|
1
|
+
const { assert } = require('chai');
|
2
|
+
|
3
|
+
describe('top level util functions', async()=> {
|
4
|
+
it('should be able to get eyefeats', async()=>{
|
5
|
+
const eyefeats = await page.evaluate(async() =>{
|
6
|
+
const videoElementCanvas = document.getElementById('webgazerVideoCanvas')
|
7
|
+
return await webgazer.getTracker().getEyePatches(videoElementCanvas,videoElementCanvas.width,videoElementCanvas.height)
|
8
|
+
})
|
9
|
+
assert.isNotNull(eyefeats)
|
10
|
+
})
|
11
|
+
it('should be able to resize an eye', async() => {
|
12
|
+
const resized_eye = await page.evaluate(async() => {
|
13
|
+
const videoElementCanvas = document.getElementById('webgazerVideoCanvas')
|
14
|
+
const eyeFeatures = await webgazer.getTracker().getEyePatches(videoElementCanvas,videoElementCanvas.width,videoElementCanvas.height)
|
15
|
+
|
16
|
+
return Array.from(await webgazer.util.resizeEye(eyeFeatures.left,6,10).data);
|
17
|
+
})
|
18
|
+
assert.isNotNull(resized_eye)
|
19
|
+
})
|
20
|
+
it('should be able to grayscale an image', async() =>{
|
21
|
+
const grayscale = await page.evaluate(async() => {
|
22
|
+
const videoElementCanvas = document.getElementById('webgazerVideoCanvas')
|
23
|
+
const eyeFeatures = await webgazer.getTracker().getEyePatches(videoElementCanvas,videoElementCanvas.width,videoElementCanvas.height)
|
24
|
+
const resized_left = await webgazer.util.resizeEye(eyeFeatures.left,6,10)
|
25
|
+
return Array.from(await webgazer.util.grayscale(resized_left.data,eyeFeatures.width,eyeFeatures.height))
|
26
|
+
})
|
27
|
+
assert.isNotNull(grayscale)
|
28
|
+
|
29
|
+
})
|
30
|
+
it('should be able to equalize a grayscaled image', async() =>{
|
31
|
+
const equalizeHistogram = await page.evaluate(async() => {
|
32
|
+
const videoElementCanvas = document.getElementById('webgazerVideoCanvas')
|
33
|
+
const eyeFeatures = await webgazer.getTracker().getEyePatches(videoElementCanvas,videoElementCanvas.width,videoElementCanvas.height)
|
34
|
+
const resized_left = await webgazer.util.resizeEye(eyeFeatures.left,6,10)
|
35
|
+
const grayscale = await webgazer.util.grayscale(resized_left.data,eyeFeatures.width,eyeFeatures.height)
|
36
|
+
return await webgazer.util.equalizeHistogram(grayscale,5,[])
|
37
|
+
})
|
38
|
+
assert.isNotNull(equalizeHistogram)
|
39
|
+
})
|
40
|
+
it('bound should adjust values to be within the appropriate range', async() =>{
|
41
|
+
const width = await page.evaluate(async() => {
|
42
|
+
return Math.max(document.documentElement.clientWidth, window.innerWidth || 0)
|
43
|
+
})
|
44
|
+
const height = await page.evaluate(async() => {
|
45
|
+
return Math.max(document.documentElement.clientHeight, window.innerHeight || 0)
|
46
|
+
})
|
47
|
+
const lower_bound = await page.evaluate(async() => {
|
48
|
+
return await webgazer.util.bound({x:-100,y:-100})
|
49
|
+
})
|
50
|
+
assert.equal(lower_bound.x,0)
|
51
|
+
assert.equal(lower_bound.y,0)
|
52
|
+
const upper_bound = await page.evaluate(async(width,height) => {
|
53
|
+
return await webgazer.util.bound({x:width+10,y:height+10})
|
54
|
+
}, width,height)
|
55
|
+
assert.equal(upper_bound.x,width)
|
56
|
+
assert.equal(upper_bound.y,height)
|
57
|
+
})
|
58
|
+
//TO-DO? DataWindow testing
|
59
|
+
|
60
|
+
})
|