Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spec: willReadFrequently #407

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
56 changes: 28 additions & 28 deletions build/tracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
tracking.trackCanvasInternal_ = function(element, tracker) {
var width = element.width;
var height = element.height;
var context = element.getContext('2d');
var context = element.getContext('2d', { willReadFrequently: true });
var imageData = context.getImageData(0, 0, width, height);
tracker.track(imageData.data, width, height);
};
Expand Down Expand Up @@ -232,7 +232,7 @@
*/
tracking.trackVideo_ = function(element, tracker) {
var canvas = document.createElement('canvas');
var context = canvas.getContext('2d');
var context = canvas.getContext('2d', { willReadFrequently: true });
var width;
var height;

Expand Down Expand Up @@ -459,7 +459,7 @@
var img = new window.Image();
img.crossOrigin = '*';
img.onload = function() {
var context = canvas.getContext('2d');
var context = canvas.getContext('2d', { willReadFrequently: true });
canvas.width = width;
canvas.height = height;
context.drawImage(img, x, y, width, height);
Expand Down Expand Up @@ -1737,7 +1737,7 @@
};

/**
* Calculates the per-element subtraction of two NxM matrices and returns a
* Calculates the per-element subtraction of two NxM matrices and returns a
* new NxM matrix as the result.
* @param {matrix} a The first matrix.
* @param {matrix} a The second matrix.
Expand All @@ -1747,7 +1747,7 @@
var res = tracking.Matrix.clone(a);
for(var i=0; i < res.length; i++){
for(var j=0; j < res[i].length; j++){
res[i][j] -= b[i][j];
res[i][j] -= b[i][j];
}
}
return res;
Expand All @@ -1764,7 +1764,7 @@
var res = tracking.Matrix.clone(a);
for(var i=0; i < res.length; i++){
for(var j=0; j < res[i].length; j++){
res[i][j] += b[i][j];
res[i][j] += b[i][j];
}
}
return res;
Expand All @@ -1785,7 +1785,7 @@
temp[i] = new Array(width);
var j = width;
while(j--) temp[i][j] = src[i][j];
}
}
return temp;
}

Expand Down Expand Up @@ -1833,7 +1833,7 @@
for (var i = 0; i < a.length; i++) {
res[i] = new Array(b[0].length);
for (var j = 0; j < b[0].length; j++) {
res[i][j] = 0;
res[i][j] = 0;
for (var k = 0; k < a[0].length; k++) {
res[i][j] += a[i][k] * b[k][j];
}
Expand Down Expand Up @@ -1882,7 +1882,7 @@

var a = tracking.Matrix.sub(src, deltaFull);
var b = tracking.Matrix.transpose(a);
var covar = tracking.Matrix.mul(b,a);
var covar = tracking.Matrix.mul(b,a);
return [covar, mean];

}
Expand Down Expand Up @@ -2631,7 +2631,7 @@
tracking.inherits(tracking.LandmarksTracker, tracking.ObjectTracker);

tracking.LandmarksTracker.prototype.track = function(pixels, width, height) {

var image = {
'data': pixels,
'width': width,
Expand All @@ -2640,8 +2640,8 @@

var classifier = tracking.ViolaJones.classifiers['face'];

var faces = tracking.ViolaJones.detect(pixels, width, height,
this.getInitialScale(), this.getScaleFactor(), this.getStepSize(),
var faces = tracking.ViolaJones.detect(pixels, width, height,
this.getInitialScale(), this.getScaleFactor(), this.getStepSize(),
this.getEdgesDensity(), classifier);

var landmarks = tracking.LBF.align(pixels, width, height, faces);
Expand Down Expand Up @@ -2720,7 +2720,7 @@
* @param {matrix} currentShapes The landmarks shapes.
* @param {array} boudingBoxes The bounding boxes of the faces.
*/
tracking.LBF.Regressor.prototype.applyGlobalPrediction = function(binaryFeatures, models, currentShapes,
tracking.LBF.Regressor.prototype.applyGlobalPrediction = function(binaryFeatures, models, currentShapes,
boundingBoxes){

var residual = currentShapes[0].length * 2;
Expand Down Expand Up @@ -2758,7 +2758,7 @@
};

/**
* Derives the binary features from the image for each landmark.
* Derives the binary features from the image for each landmark.
* @param {object} forest The random forest to search for the best binary feature match.
* @param {array} images The images with pixels in a grayscale linear array.
* @param {array} currentShapes The current landmarks shape.
Expand All @@ -2785,11 +2785,11 @@

var projectedShape = tracking.LBF.unprojectShapeToBoundingBox_(currentShapes[i], boundingBoxes[i]);
var transform = tracking.LBF.similarityTransform_(projectedShape, meanShape);

for(var j=0; j < forest.landmarkNum; j++){
for(var k=0; k < forest.maxNumTrees; k++){

var binaryCode = tracking.LBF.Regressor.getCodeFromTree(forest.rfs[j][k], images[i],
var binaryCode = tracking.LBF.Regressor.getCodeFromTree(forest.rfs[j][k], images[i],
currentShapes[i], boundingBoxes[i], transform[0], transform[1]);

var index = j*forest.maxNumTrees + k;
Expand All @@ -2808,11 +2808,11 @@
/**
* Gets the binary code for a specific tree in a random forest. For each landmark,
* the position from two pre-defined points are recovered from the training data
* and then the intensity of the pixels corresponding to these points is extracted
* and then the intensity of the pixels corresponding to these points is extracted
* from the image and used to traverse the trees in the random forest. At the end,
* the ending nodes will be represented by 1, and the remaining nodes by 0.
*
* +--------------------------- Random Forest -----------------------------+
*
* +--------------------------- Random Forest -----------------------------+
* | Ø = Ending leaf |
* | |
* | O O O O O |
Expand Down Expand Up @@ -2840,7 +2840,7 @@
var bincode = 0;

while(true){

var x1 = Math.cos(tree.nodes[current].feats[0]) * tree.nodes[current].feats[2] * tree.maxRadioRadius * boundingBox.width;
var y1 = Math.sin(tree.nodes[current].feats[0]) * tree.nodes[current].feats[2] * tree.maxRadioRadius * boundingBox.height;
var x2 = Math.cos(tree.nodes[current].feats[1]) * tree.nodes[current].feats[3] * tree.maxRadioRadius * boundingBox.width;
Expand All @@ -2861,7 +2861,7 @@
var real_y2 = Math.floor(project_y2 + shape[tree.landmarkID][1]);
real_x2 = Math.max(0.0, Math.min(real_x2, image.height - 1.0));
real_y2 = Math.max(0.0, Math.min(real_y2, image.width - 1.0));
var pdf = Math.floor(image.data[real_y1*image.width + real_x1]) -
var pdf = Math.floor(image.data[real_y1*image.width + real_x1]) -
Math.floor(image.data[real_y2 * image.width +real_x2]);

if(pdf < tree.nodes[current].thresh){
Expand Down Expand Up @@ -2896,14 +2896,14 @@
* discriminative local binary features for each landmark independently.
* The obtained local binary features are used to learn a linear regression
* that later will be used to guide the landmarks in the alignment phase.
*
*
* @authors: VoxarLabs Team (http://cin.ufpe.br/~voxarlabs)
* Lucas Figueiredo <lsf@cin.ufpe.br>, Thiago Menezes <tmc2@cin.ufpe.br>,
* Thiago Domingues <tald@cin.ufpe.br>, Rafael Roberto <rar3@cin.ufpe.br>,
* Thulio Araujo <tlsa@cin.ufpe.br>, Joao Victor <jvfl@cin.ufpe.br>,
* Tomer Simis <tls@cin.ufpe.br>)
*/

/**
* Holds the maximum number of stages that will be used in the alignment algorithm.
* Each stage contains a different set of random forests and retrieves the binary
Expand All @@ -2914,14 +2914,14 @@
tracking.LBF.maxNumStages = 4;

/**
* Holds the regressor that will be responsible for extracting the local features from
* Holds the regressor that will be responsible for extracting the local features from
* the image and guide the landmarks using the training data.
* @type {object}
* @protected
* @static
*/
tracking.LBF.regressor_ = null;
tracking.LBF.regressor_ = null;

/**
* Generates a set of landmarks for a set of faces
* @param {pixels} pixels The pixels in a linear [r,g,b,a,...] array.
Expand Down Expand Up @@ -3079,7 +3079,7 @@
this.maxNumTrees = tracking.LBF.RegressorData[forestIndex].max_numtrees;
this.landmarkNum = tracking.LBF.RegressorData[forestIndex].num_landmark;
this.maxDepth = tracking.LBF.RegressorData[forestIndex].max_depth;
this.stages = tracking.LBF.RegressorData[forestIndex].stages;
this.stages = tracking.LBF.RegressorData[forestIndex].stages;

this.rfs = new Array(this.landmarkNum);
for(var i=0; i < this.landmarkNum; i++){
Expand Down Expand Up @@ -3108,4 +3108,4 @@
this.leafnodes = data.id_leafnodes;
}

}());
}());
4 changes: 2 additions & 2 deletions src/tracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
tracking.trackCanvasInternal_ = function(element, tracker) {
var width = element.width;
var height = element.height;
var context = element.getContext('2d');
var context = element.getContext('2d', { willReadFrequently: true });
var imageData = context.getImageData(0, 0, width, height);
tracker.track(imageData.data, width, height);
};
Expand Down Expand Up @@ -225,7 +225,7 @@
*/
tracking.trackVideo_ = function(element, tracker) {
var canvas = document.createElement('canvas');
var context = canvas.getContext('2d');
var context = canvas.getContext('2d', { willReadFrequently: true });
var width;
var height;

Expand Down