From 13e9d3429cfcd5362be3389fb9beb20b07b6977f Mon Sep 17 00:00:00 2001 From: sac Date: Fri, 10 Aug 2018 13:31:21 -0300 Subject: [PATCH 1/2] stop user media function --- build/tracking-min.js | 2 +- build/tracking.js | 97 +++++++++++++++++++++++++++++++++---------- src/tracking.js | 12 ++++++ 3 files changed, 89 insertions(+), 22 deletions(-) diff --git a/build/tracking-min.js b/build/tracking-min.js index 125f915..eeb6176 100644 --- a/build/tracking-min.js +++ b/build/tracking-min.js @@ -5,4 +5,4 @@ * @link http://trackingjs.com * @license BSD */ -!function(t,r){t.tracking=t.tracking||{},tracking.inherits=function(t,r){function n(){}n.prototype=r.prototype,t.superClass_=r.prototype,t.prototype=new n,t.prototype.constructor=t,t.base=function(t,n){var e=Array.prototype.slice.call(arguments,2);return r.prototype[n].apply(t,e)}},tracking.initUserMedia_=function(r,n){t.navigator.mediaDevices.getUserMedia({video:!0,audio:!(!n||!n.audio)}).then(function(t){r.srcObject=t})["catch"](function(t){throw Error("Cannot capture user camera.")})},tracking.isNode=function(t){return t.nodeType||this.isWindow(t)},tracking.isWindow=function(t){return!!(t&&t.alert&&t.document)},tracking.one=function(t,r){return this.isNode(t)?t:(r||document).querySelector(t)},tracking.track=function(t,r,n){if(t=tracking.one(t),!t)throw new Error("Element not found, try a different element or selector.");if(!r)throw new Error("Tracker not specified, try `tracking.track(element, new tracking.FaceTracker())`.");switch(t.nodeName.toLowerCase()){case"canvas":return this.trackCanvas_(t,r,n);case"img":return this.trackImg_(t,r,n);case"video":return n&&n.camera&&this.initUserMedia_(t,n),this.trackVideo_(t,r,n);default:throw new Error("Element not supported, try in a canvas, img, or video.")}},tracking.trackCanvas_=function(t,r){var n=this,e=new tracking.TrackerTask(r);return e.on("run",function(){n.trackCanvasInternal_(t,r)}),e.run()},tracking.trackCanvasInternal_=function(t,r){var n=t.width,e=t.height,a=t.getContext("2d"),i=a.getImageData(0,0,n,e);r.track(i.data,n,e)},tracking.trackImg_=function(t,r){var n=t.width,e=t.height,a=document.createElement("canvas");a.width=n,a.height=e;var i=new tracking.TrackerTask(r);return i.on("run",function(){tracking.Canvas.loadImage(a,t.src,0,0,n,e,function(){tracking.trackCanvasInternal_(a,r)})}),i.run()},tracking.trackVideo_=function(r,n){var e,a,i=document.createElement("canvas"),o=i.getContext("2d"),c=function(){e=r.offsetWidth,a=r.offsetHeight,i.width=e,i.height=a};c(),r.addEventListener("resize",c);var s,g=function(){s=t.requestAnimationFrame(function(){if(r.readyState===r.HAVE_ENOUGH_DATA){try{o.drawImage(r,0,0,e,a)}catch(t){}tracking.trackCanvasInternal_(i,n)}g()})},h=new tracking.TrackerTask(n);return h.on("stop",function(){t.cancelAnimationFrame(s)}),h.on("run",function(){g()}),h.run()},t.URL||(t.URL=t.URL||t.webkitURL||t.msURL||t.oURL),navigator.getUserMedia||(navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia)}(window),function(){tracking.EventEmitter=function(){},tracking.EventEmitter.prototype.events_=null,tracking.EventEmitter.prototype.addListener=function(t,r){if("function"!=typeof r)throw new TypeError("Listener must be a function");return this.events_||(this.events_={}),this.emit("newListener",t,r),this.events_[t]||(this.events_[t]=[]),this.events_[t].push(r),this},tracking.EventEmitter.prototype.listeners=function(t){return this.events_&&this.events_[t]},tracking.EventEmitter.prototype.emit=function(t){var r=this.listeners(t);if(r){for(var n=Array.prototype.slice.call(arguments,1),e=0;e>2),i=0,o=0,c=0;c0&&(s=new Int32Array(r*n)),tracking.Image.computeIntegralImage(t,r,n,k,f,u,s);for(var l=c[0],m=c[1],d=e*a,v=d*l|0,p=d*m|0;v0&&this.isTriviallyExcluded(o,s,w,T,r,v,p)||this.evalStages_(c,k,f,u,w,T,r,v,p,d)&&(h[g++]={width:v,height:p,x:T,y:w});d*=a,v=d*l|0,p=d*m|0}return this.mergeRectangles_(h)},tracking.ViolaJones.isTriviallyExcluded=function(t,r,n,e,a,i,o){var c=n*a+e,s=c+i,g=c+o*a,h=g+i,k=(r[c]-r[s]-r[g]+r[h])/(i*o*255);return k0&&(v=Math.sqrt(d));for(var p=t.length,y=2;y=this.REGIONS_OVERLAP&&h/(f*(k/f))>=this.REGIONS_OVERLAP&&r.union(n,a)}}for(var u={},l=0;l>1)*(this.N>>5)),a=0,i=this.getRandomOffsets_(r),o=0,c=0;c>1,i=n.length>>1,o=new Array(a),c=0;c>5;fn},tracking.Fast.isCorner=function(t,r,n){if(this.isTriviallyExcluded(r,t,n))return!1;for(var e=0;e<16;e++){for(var a=!0,i=!0,o=0;o<9;o++){var c=r[e+o&15];if(!this.isBrighter(t,c,n)&&(i=!1,a===!1))break;if(!this.isDarker(t,c,n)&&(a=!1,i===!1))break}if(i||a)return!0}return!1},tracking.Fast.isDarker=function(t,r,n){return r-t>n},tracking.Fast.isTriviallyExcluded=function(t,r,n){var e=0,a=t[8],i=t[12],o=t[4],c=t[0];return this.isBrighter(c,r,n)&&e++,this.isBrighter(o,r,n)&&e++,this.isBrighter(a,r,n)&&e++,this.isBrighter(i,r,n)&&e++,e<3&&(e=0,this.isDarker(c,r,n)&&e++,this.isDarker(o,r,n)&&e++,this.isDarker(a,r,n)&&e++,this.isDarker(i,r,n)&&e++,e<3)},tracking.Fast.getCircleOffsets_=function(t){if(this.circles_[t])return this.circles_[t];var r=new Int32Array(16);return r[0]=-t-t-t,r[1]=r[0]+1,r[2]=r[1]+t+1,r[3]=r[2]+t+1,r[4]=r[3]+t,r[5]=r[4]+t,r[6]=r[5]+t-1,r[7]=r[6]+t-1,r[8]=r[7]-1,r[9]=r[8]-1,r[10]=r[9]-t-1,r[11]=r[10]-t-1,r[12]=r[11]-t,r[13]=r[12]-t,r[14]=r[13]-t+1,r[15]=r[14]-t+1,this.circles_[t]=r,r}}(),function(){tracking.Math={},tracking.Math.distance=function(t,r,n,e){var a=n-t,i=e-r;return Math.sqrt(a*a+i*i)},tracking.Math.hammingWeight=function(t){return t-=t>>1&1431655765,t=(858993459&t)+(t>>2&858993459),16843009*(t+(t>>4)&252645135)>>24},tracking.Math.uniformRandom=function(t,r){return t+Math.random()*(r-t)},tracking.Math.intersectRect=function(t,r,n,e,a,i,o,c){return!(a>n||oe||cn&&(n=c),se&&(e=s)}return{width:n-a,height:e-i,x:a,y:i}},tracking.ColorTracker.prototype.getColors=function(){return this.colors},tracking.ColorTracker.prototype.getMinDimension=function(){return this.minDimension},tracking.ColorTracker.prototype.getMaxDimension=function(){return this.maxDimension},tracking.ColorTracker.prototype.getMinGroupSize=function(){return this.minGroupSize},tracking.ColorTracker.prototype.getNeighboursForWidth_=function(t){if(tracking.ColorTracker.neighbours_[t])return tracking.ColorTracker.neighbours_[t];var r=new Int32Array(8);return r[0]=4*-t,r[1]=4*-t+4,r[2]=4,r[3]=4*t+4,r[4]=4*t,r[5]=4*t-4,r[6]=-4,r[7]=4*-t-4,tracking.ColorTracker.neighbours_[t]=r,r},tracking.ColorTracker.prototype.mergeRectangles_=function(t){for(var r,n=[],e=this.getMinDimension(),a=this.getMaxDimension(),i=0;i=e&&o.height>=e&&o.width<=a&&o.height<=a&&n.push(o)}return n},tracking.ColorTracker.prototype.setColors=function(t){this.colors=t},tracking.ColorTracker.prototype.setMinDimension=function(t){this.minDimension=t},tracking.ColorTracker.prototype.setMaxDimension=function(t){this.maxDimension=t},tracking.ColorTracker.prototype.setMinGroupSize=function(t){this.minGroupSize=t},tracking.ColorTracker.prototype.track=function(t,r,n){var e=this,a=this.getColors();if(!a)throw new Error('Colors not specified, try `new tracking.ColorTracker("magenta")`.');var i=[];a.forEach(function(a){i=i.concat(e.trackColor_(t,r,n,a))}),this.emit("track",{data:i})},tracking.ColorTracker.prototype.trackColor_=function(n,e,a,i){var o,c,s,g,h,k=tracking.ColorTracker.knownColors_[i],f=new Int32Array(n.length>>2),u=new Int8Array(n.length),l=this.getMinGroupSize(),m=this.getNeighboursForWidth_(e),d=new Int32Array(n.length),v=[],p=-4;if(!k)return v;for(var y=0;y=0;)if(s=d[h--],c=d[h--],g=d[h--],k(n[g],n[g+1],n[g+2],n[g+3],g,c,s)){f[o++]=s,f[o++]=c;for(var T=0;T=0&&M=0&&_=l){var C=this.calculateDimensions_(f,o);C&&(C.color=i,v.push(C))}}return this.mergeRectangles_(v)},tracking.ColorTracker.registerColor("cyan",function(t,r,n){var e=50,a=70,i=t-0,o=r-255,c=n-255;return r-t>=e&&n-t>=a||i*i+o*o+c*c<6400}),tracking.ColorTracker.registerColor("magenta",function(t,r,n){var e=50,a=t-255,i=r-0,o=n-255;return t-r>=e&&n-r>=e||a*a+i*i+o*o<19600}),tracking.ColorTracker.registerColor("yellow",function(t,r,n){var e=50,a=t-255,i=r-255,o=n-0;return t-n>=e&&r-n>=e||a*a+i*i+o*o<1e4});var t=new Int32Array([-1,-1,0,1,1,1,0,-1]),r=new Int32Array([0,1,1,1,0,-1,-1,-1])}(),function(){tracking.ObjectTracker=function(t){tracking.ObjectTracker.base(this,"constructor"),t&&(Array.isArray(t)||(t=[t]),Array.isArray(t)&&t.forEach(function(r,n){if("string"==typeof r&&(t[n]=tracking.ViolaJones.classifiers[r]),!t[n])throw new Error('Object classifier not valid, try `new tracking.ObjectTracker("face")`.')})),this.setClassifiers(t)},tracking.inherits(tracking.ObjectTracker,tracking.Tracker),tracking.ObjectTracker.prototype.edgesDensity=.2,tracking.ObjectTracker.prototype.initialScale=1,tracking.ObjectTracker.prototype.scaleFactor=1.25,tracking.ObjectTracker.prototype.stepSize=1.5,tracking.ObjectTracker.prototype.getClassifiers=function(){return this.classifiers},tracking.ObjectTracker.prototype.getEdgesDensity=function(){return this.edgesDensity},tracking.ObjectTracker.prototype.getInitialScale=function(){return this.initialScale},tracking.ObjectTracker.prototype.getScaleFactor=function(){return this.scaleFactor},tracking.ObjectTracker.prototype.getStepSize=function(){return this.stepSize},tracking.ObjectTracker.prototype.track=function(t,r,n){var e=this,a=this.getClassifiers();if(!a)throw new Error('Object classifier not specified, try `new tracking.ObjectTracker("face")`.');var i=[];a.forEach(function(a){i=i.concat(tracking.ViolaJones.detect(t,r,n,e.getInitialScale(),e.getScaleFactor(),e.getStepSize(),e.getEdgesDensity(),a))}),this.emit("track",{data:i})},tracking.ObjectTracker.prototype.setClassifiers=function(t){this.classifiers=t},tracking.ObjectTracker.prototype.setEdgesDensity=function(t){this.edgesDensity=t},tracking.ObjectTracker.prototype.setInitialScale=function(t){this.initialScale=t},tracking.ObjectTracker.prototype.setScaleFactor=function(t){this.scaleFactor=t},tracking.ObjectTracker.prototype.setStepSize=function(t){this.stepSize=t}}(),function(){tracking.LandmarksTracker=function(){tracking.LandmarksTracker.base(this,"constructor")},tracking.inherits(tracking.LandmarksTracker,tracking.ObjectTracker),tracking.LandmarksTracker.prototype.track=function(t,r,n){var e=tracking.ViolaJones.classifiers.face,a=tracking.ViolaJones.detect(t,r,n,this.getInitialScale(),this.getScaleFactor(),this.getStepSize(),this.getEdgesDensity(),e),i=tracking.LBF.align(t,r,n,a);this.emit("track",{data:{faces:a,landmarks:i}})}}(),function(){tracking.LBF={},tracking.LBF.Regressor=function(t){this.maxNumStages=t,this.rfs=new Array(t),this.models=new Array(t);for(var r=0;r>2,i=e?new Uint32Array(a):new Uint8Array(a),o=new Uint32Array(r.buffer||new Uint8Array(r).buffer),c=0,s=0,g=0;if(e)for(;c>>16&255)+46871*(s>>>8&255)+4732*(255&s)>>>16,i[c++]=65793*g|4278190080&s;else for(;c>>16&255)+46871*(s>>>8&255)+4732*(255&s)>>>16,i[c++]=g;return new Uint8Array(i.buffer)},tracking.Image.horizontalConvolve=function(r,t,n,e,a){for(var i=e.length,o=Math.floor(i/2),c=new Float32Array(t*n*4),s=a?1:0,g=0;g0&&(s=new Int32Array(t*n)),tracking.Image.computeIntegralImage(r,t,n,k,f,u,s);for(var l=c[0],m=c[1],d=e*a,v=d*l|0,p=d*m|0;v0&&this.isTriviallyExcluded(o,s,w,T,t,v,p)||this.evalStages_(c,k,f,u,w,T,t,v,p,d)&&(h[g++]={width:v,height:p,x:T,y:w});d*=a,v=d*l|0,p=d*m|0}return this.mergeRectangles_(h)},tracking.ViolaJones.isTriviallyExcluded=function(r,t,n,e,a,i,o){var c=n*a+e,s=c+i,g=c+o*a,h=g+i,k=(t[c]-t[s]-t[g]+t[h])/(i*o*255);return k0&&(v=Math.sqrt(d));for(var p=r.length,y=2;y=this.REGIONS_OVERLAP&&h/(f*(k/f))>=this.REGIONS_OVERLAP&&t.union(n,a)}}for(var u={},l=0;l>1)*(this.N>>5)),a=0,i=this.getRandomOffsets_(t),o=0,c=0;c>1,i=n.length>>1,o=new Array(a),c=0;c>5;fn},tracking.Fast.isCorner=function(r,t,n){if(this.isTriviallyExcluded(t,r,n))return!1;for(var e=0;e<16;e++){for(var a=!0,i=!0,o=0;o<9;o++){var c=t[e+o&15];if(!this.isBrighter(r,c,n)&&(i=!1,a===!1))break;if(!this.isDarker(r,c,n)&&(a=!1,i===!1))break}if(i||a)return!0}return!1},tracking.Fast.isDarker=function(r,t,n){return t-r>n},tracking.Fast.isTriviallyExcluded=function(r,t,n){var e=0,a=r[8],i=r[12],o=r[4],c=r[0];return this.isBrighter(c,t,n)&&e++,this.isBrighter(o,t,n)&&e++,this.isBrighter(a,t,n)&&e++,this.isBrighter(i,t,n)&&e++,e<3&&(e=0,this.isDarker(c,t,n)&&e++,this.isDarker(o,t,n)&&e++,this.isDarker(a,t,n)&&e++,this.isDarker(i,t,n)&&e++,e<3)},tracking.Fast.getCircleOffsets_=function(r){if(this.circles_[r])return this.circles_[r];var t=new Int32Array(16);return t[0]=-r-r-r,t[1]=t[0]+1,t[2]=t[1]+r+1,t[3]=t[2]+r+1,t[4]=t[3]+r,t[5]=t[4]+r,t[6]=t[5]+r-1,t[7]=t[6]+r-1,t[8]=t[7]-1,t[9]=t[8]-1,t[10]=t[9]-r-1,t[11]=t[10]-r-1,t[12]=t[11]-r,t[13]=t[12]-r,t[14]=t[13]-r+1,t[15]=t[14]-r+1,this.circles_[r]=t,t}}(),function(){tracking.Math={},tracking.Math.distance=function(r,t,n,e){var a=n-r,i=e-t;return Math.sqrt(a*a+i*i)},tracking.Math.hammingWeight=function(r){return r-=r>>1&1431655765,r=(858993459&r)+(r>>2&858993459),16843009*(r+(r>>4)&252645135)>>24},tracking.Math.uniformRandom=function(r,t){return r+Math.random()*(t-r)},tracking.Math.intersectRect=function(r,t,n,e,a,i,o,c){return!(a>n||oe||cn&&(n=c),se&&(e=s)}return{width:n-a,height:e-i,x:a,y:i}},tracking.ColorTracker.prototype.getColors=function(){return this.colors},tracking.ColorTracker.prototype.getMinDimension=function(){return this.minDimension},tracking.ColorTracker.prototype.getMaxDimension=function(){return this.maxDimension},tracking.ColorTracker.prototype.getMinGroupSize=function(){return this.minGroupSize},tracking.ColorTracker.prototype.getNeighboursForWidth_=function(r){if(tracking.ColorTracker.neighbours_[r])return tracking.ColorTracker.neighbours_[r];var t=new Int32Array(8);return t[0]=4*-r,t[1]=4*-r+4,t[2]=4,t[3]=4*r+4,t[4]=4*r,t[5]=4*r-4,t[6]=-4,t[7]=4*-r-4,tracking.ColorTracker.neighbours_[r]=t,t},tracking.ColorTracker.prototype.mergeRectangles_=function(r){for(var t,n=[],e=this.getMinDimension(),a=this.getMaxDimension(),i=0;i=e&&o.height>=e&&o.width<=a&&o.height<=a&&n.push(o)}return n},tracking.ColorTracker.prototype.setColors=function(r){this.colors=r},tracking.ColorTracker.prototype.setMinDimension=function(r){this.minDimension=r},tracking.ColorTracker.prototype.setMaxDimension=function(r){this.maxDimension=r},tracking.ColorTracker.prototype.setMinGroupSize=function(r){this.minGroupSize=r},tracking.ColorTracker.prototype.track=function(r,t,n){var e=this,a=this.getColors();if(!a)throw new Error('Colors not specified, try `new tracking.ColorTracker("magenta")`.');var i=[];a.forEach(function(a){i=i.concat(e.trackColor_(r,t,n,a))}),this.emit("track",{data:i})},tracking.ColorTracker.prototype.trackColor_=function(n,e,a,i){var o,c,s,g,h,k=tracking.ColorTracker.knownColors_[i],f=new Int32Array(n.length>>2),u=new Int8Array(n.length),l=this.getMinGroupSize(),m=this.getNeighboursForWidth_(e),d=new Int32Array(n.length),v=[],p=-4;if(!k)return v;for(var y=0;y=0;)if(s=d[h--],c=d[h--],g=d[h--],k(n[g],n[g+1],n[g+2],n[g+3],g,c,s)){f[o++]=s,f[o++]=c;for(var T=0;T=0&&M=0&&_=l){var C=this.calculateDimensions_(f,o);C&&(C.color=i,v.push(C))}}return this.mergeRectangles_(v)},tracking.ColorTracker.registerColor("cyan",function(r,t,n){var e=50,a=70,i=r-0,o=t-255,c=n-255;return t-r>=e&&n-r>=a||i*i+o*o+c*c<6400}),tracking.ColorTracker.registerColor("magenta",function(r,t,n){var e=50,a=r-255,i=t-0,o=n-255;return r-t>=e&&n-t>=e||a*a+i*i+o*o<19600}),tracking.ColorTracker.registerColor("yellow",function(r,t,n){var e=50,a=r-255,i=t-255,o=n-0;return r-n>=e&&t-n>=e||a*a+i*i+o*o<1e4});var r=new Int32Array([-1,-1,0,1,1,1,0,-1]),t=new Int32Array([0,1,1,1,0,-1,-1,-1])}(),function(){tracking.ObjectTracker=function(r){tracking.ObjectTracker.base(this,"constructor"),r&&(Array.isArray(r)||(r=[r]),Array.isArray(r)&&r.forEach(function(t,n){if("string"==typeof t&&(r[n]=tracking.ViolaJones.classifiers[t]),!r[n])throw new Error('Object classifier not valid, try `new tracking.ObjectTracker("face")`.')})),this.setClassifiers(r)},tracking.inherits(tracking.ObjectTracker,tracking.Tracker),tracking.ObjectTracker.prototype.edgesDensity=.2,tracking.ObjectTracker.prototype.initialScale=1,tracking.ObjectTracker.prototype.scaleFactor=1.25,tracking.ObjectTracker.prototype.stepSize=1.5,tracking.ObjectTracker.prototype.getClassifiers=function(){return this.classifiers},tracking.ObjectTracker.prototype.getEdgesDensity=function(){return this.edgesDensity},tracking.ObjectTracker.prototype.getInitialScale=function(){return this.initialScale},tracking.ObjectTracker.prototype.getScaleFactor=function(){return this.scaleFactor},tracking.ObjectTracker.prototype.getStepSize=function(){return this.stepSize},tracking.ObjectTracker.prototype.track=function(r,t,n){var e=this,a=this.getClassifiers();if(!a)throw new Error('Object classifier not specified, try `new tracking.ObjectTracker("face")`.');var i=[];a.forEach(function(a){i=i.concat(tracking.ViolaJones.detect(r,t,n,e.getInitialScale(),e.getScaleFactor(),e.getStepSize(),e.getEdgesDensity(),a))}),this.emit("track",{data:i})},tracking.ObjectTracker.prototype.setClassifiers=function(r){this.classifiers=r},tracking.ObjectTracker.prototype.setEdgesDensity=function(r){this.edgesDensity=r},tracking.ObjectTracker.prototype.setInitialScale=function(r){this.initialScale=r},tracking.ObjectTracker.prototype.setScaleFactor=function(r){this.scaleFactor=r},tracking.ObjectTracker.prototype.setStepSize=function(r){this.stepSize=r}}(),function(){tracking.LandmarksTracker=function(){tracking.LandmarksTracker.base(this,"constructor")},tracking.inherits(tracking.LandmarksTracker,tracking.ObjectTracker),tracking.LandmarksTracker.prototype.track=function(r,t,n){var e=tracking.ViolaJones.classifiers.face,a=tracking.ViolaJones.detect(r,t,n,this.getInitialScale(),this.getScaleFactor(),this.getStepSize(),this.getEdgesDensity(),e),i=tracking.LBF.align(r,t,n,a);this.emit("track",{data:{faces:a,landmarks:i}})}}(),function(){tracking.LBF={},tracking.LBF.Regressor=function(r){this.maxNumStages=r,this.rfs=new Array(r),this.models=new Array(r);for(var t=0;t> 2); - var p = 0; - var w = 0; - for (var i = 0; i < height; i++) { - for (var j = 0; j < width; j++) { - var value = pixels[w] * 0.299 + pixels[w + 1] * 0.587 + pixels[w + 2] * 0.114; - gray[p++] = value; - if (fillRGBA) { - gray[p++] = value; - gray[p++] = value; - gray[p++] = pixels[w + 3]; - } + /* + Performance result (rough EST. - image size, CPU arch. will affect): + https://jsperf.com/tracking-new-image-to-grayscale + + Firefox v.60b: + fillRGBA Gray only + Old 11 551 OPs/sec + New 3548 6487 OPs/sec + --------------------------------- + 322.5x 11.8x faster + + Chrome v.67b: + fillRGBA Gray only + Old 291 489 OPs/sec + New 6975 6635 OPs/sec + --------------------------------- + 24.0x 13.6x faster + + - Ken Nilsen / epistemex + */ - w += 4; + var len = pixels.length>>2; + var gray = fillRGBA ? new Uint32Array(len) : new Uint8Array(len); + var data32 = new Uint32Array(pixels.buffer || new Uint8Array(pixels).buffer); + var i = 0; + var c = 0; + var luma = 0; + + // unrolled loops to not have to check fillRGBA each iteration + if (fillRGBA) { + while(i < len) { + // Entire pixel in little-endian order (ABGR) + c = data32[i]; + + // Using the more up-to-date REC/BT.709 approx. weights for luma instead: [0.2126, 0.7152, 0.0722]. + // luma = ((c>>>16 & 0xff) * 0.2126 + (c>>>8 & 0xff) * 0.7152 + (c & 0xff) * 0.0722 + 0.5)|0; + // But I'm using scaled integers here for speed (x 0xffff). This can be improved more using 2^n + // close to the factors allowing for shift-ops (i.e. 4732 -> 4096 => .. (c&0xff) << 12 .. etc.) + // if "accuracy" is not important (luma is anyway an visual approx.): + luma = ((c>>>16&0xff) * 13933 + (c>>>8&0xff) * 46871 + (c&0xff) * 4732)>>>16; + gray[i++] = luma * 0x10101 | c & 0xff000000; } } - return gray; + else { + while(i < len) { + c = data32[i]; + luma = ((c>>>16&0xff) * 13933 + (c>>>8&0xff) * 46871 + (c&0xff) * 4732)>>>16; + // ideally, alpha should affect value here: value * (alpha/255) or with shift-ops for the above version + gray[i++] = luma; + } + } + + // Consolidate array view to byte component format independent of source view + return new Uint8Array(gray.buffer); }; /** @@ -2939,7 +2994,7 @@ tracking.LBF.maxNumStages ); } - +// NOTE: is this thesholding suitable ? if it is on image, why no skin-color filter ? and a adaptative threshold pixels = tracking.Image.grayscale(pixels, width, height, false); pixels = tracking.Image.equalizeHist(pixels, width, height); @@ -3108,4 +3163,4 @@ this.leafnodes = data.id_leafnodes; } -}()); \ No newline at end of file +}()); diff --git a/src/tracking.js b/src/tracking.js index 6fcc498..af87485 100644 --- a/src/tracking.js +++ b/src/tracking.js @@ -59,12 +59,22 @@ video: true, audio: (opt_options && opt_options.audio) ? true : false, }).then(function(stream) { + tracking.localStream = stream; element.srcObject = stream; }).catch(function(err) { throw Error('Cannot capture user camera.'); }); }; + /** + Stops the video camera media + */ + tracking.stopUserMedia = function(){ + if(tracking.localStream){ + tracking.localStream.getVideoTracks()[0].stop(); + } + }; + /** * Tests whether the object is a dom node. * @param {object} o Object to be tested. @@ -283,3 +293,5 @@ navigator.mozGetUserMedia || navigator.msGetUserMedia; } }(window)); + +module.exports = window.tracking \ No newline at end of file From c52731650f29b0d3dc94cf614e8e9dc2550652f2 Mon Sep 17 00:00:00 2001 From: sac Date: Fri, 10 Aug 2018 13:46:32 -0300 Subject: [PATCH 2/2] fix exports --- build/tracking-min.js | 2 +- build/tracking.js | 4 +++- src/tracking.js | 5 +++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/build/tracking-min.js b/build/tracking-min.js index eeb6176..2d1d495 100644 --- a/build/tracking-min.js +++ b/build/tracking-min.js @@ -5,4 +5,4 @@ * @link http://trackingjs.com * @license BSD */ -!function(r,t){r.tracking=r.tracking||{},tracking.inherits=function(r,t){function n(){}n.prototype=t.prototype,r.superClass_=t.prototype,r.prototype=new n,r.prototype.constructor=r,r.base=function(r,n){var e=Array.prototype.slice.call(arguments,2);return t.prototype[n].apply(r,e)}},tracking.initUserMedia_=function(t,n){r.navigator.mediaDevices.getUserMedia({video:!0,audio:!(!n||!n.audio)}).then(function(r){tracking.localStream=r,t.srcObject=r})["catch"](function(r){throw Error("Cannot capture user camera.")})},tracking.stopUserMedia=function(){tracking.localStream&&tracking.localStream.getVideoTracks()[0].stop()},tracking.isNode=function(r){return r.nodeType||this.isWindow(r)},tracking.isWindow=function(r){return!!(r&&r.alert&&r.document)},tracking.one=function(r,t){return this.isNode(r)?r:(t||document).querySelector(r)},tracking.track=function(r,t,n){if(r=tracking.one(r),!r)throw new Error("Element not found, try a different element or selector.");if(!t)throw new Error("Tracker not specified, try `tracking.track(element, new tracking.FaceTracker())`.");switch(r.nodeName.toLowerCase()){case"canvas":return this.trackCanvas_(r,t,n);case"img":return this.trackImg_(r,t,n);case"video":return n&&n.camera&&this.initUserMedia_(r,n),this.trackVideo_(r,t,n);default:throw new Error("Element not supported, try in a canvas, img, or video.")}},tracking.trackCanvas_=function(r,t){var n=this,e=new tracking.TrackerTask(t);return e.on("run",function(){n.trackCanvasInternal_(r,t)}),e.run()},tracking.trackCanvasInternal_=function(r,t){var n=r.width,e=r.height,a=r.getContext("2d"),i=a.getImageData(0,0,n,e);t.track(i.data,n,e)},tracking.trackImg_=function(r,t){var n=r.naturalWidth,e=r.naturalHeight,a=document.createElement("canvas");a.width=n,a.height=e;var i=new tracking.TrackerTask(t);return i.on("run",function(){tracking.Canvas.loadImage(a,r.src,0,0,n,e,function(){tracking.trackCanvasInternal_(a,t)})}),i.run()},tracking.trackVideo_=function(t,n){var e,a,i=document.createElement("canvas"),o=i.getContext("2d"),c=function(){e=t.offsetWidth,a=t.offsetHeight,i.width=e,i.height=a};c(),t.addEventListener("resize",c);var s,g=function(){s=r.requestAnimationFrame(function(){if(t.readyState===t.HAVE_ENOUGH_DATA){try{o.drawImage(t,0,0,e,a)}catch(r){}tracking.trackCanvasInternal_(i,n)}g()})},h=new tracking.TrackerTask(n);return h.on("stop",function(){r.cancelAnimationFrame(s)}),h.on("run",function(){g()}),h.run()},r.URL||(r.URL=r.URL||r.webkitURL||r.msURL||r.oURL),navigator.getUserMedia||(navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia)}(window),module.exports=window.tracking(function(){tracking.EventEmitter=function(){},tracking.EventEmitter.prototype.events_=null,tracking.EventEmitter.prototype.addListener=function(r,t){if("function"!=typeof t)throw new TypeError("Listener must be a function");return this.events_||(this.events_={}),this.emit("newListener",r,t),this.events_[r]||(this.events_[r]=[]),this.events_[r].push(t),this},tracking.EventEmitter.prototype.listeners=function(r){return this.events_&&this.events_[r]},tracking.EventEmitter.prototype.emit=function(r){var t=this.listeners(r);if(t){for(var n=Array.prototype.slice.call(arguments,1),e=0;e>2,i=e?new Uint32Array(a):new Uint8Array(a),o=new Uint32Array(r.buffer||new Uint8Array(r).buffer),c=0,s=0,g=0;if(e)for(;c>>16&255)+46871*(s>>>8&255)+4732*(255&s)>>>16,i[c++]=65793*g|4278190080&s;else for(;c>>16&255)+46871*(s>>>8&255)+4732*(255&s)>>>16,i[c++]=g;return new Uint8Array(i.buffer)},tracking.Image.horizontalConvolve=function(r,t,n,e,a){for(var i=e.length,o=Math.floor(i/2),c=new Float32Array(t*n*4),s=a?1:0,g=0;g0&&(s=new Int32Array(t*n)),tracking.Image.computeIntegralImage(r,t,n,k,f,u,s);for(var l=c[0],m=c[1],d=e*a,v=d*l|0,p=d*m|0;v0&&this.isTriviallyExcluded(o,s,w,T,t,v,p)||this.evalStages_(c,k,f,u,w,T,t,v,p,d)&&(h[g++]={width:v,height:p,x:T,y:w});d*=a,v=d*l|0,p=d*m|0}return this.mergeRectangles_(h)},tracking.ViolaJones.isTriviallyExcluded=function(r,t,n,e,a,i,o){var c=n*a+e,s=c+i,g=c+o*a,h=g+i,k=(t[c]-t[s]-t[g]+t[h])/(i*o*255);return k0&&(v=Math.sqrt(d));for(var p=r.length,y=2;y=this.REGIONS_OVERLAP&&h/(f*(k/f))>=this.REGIONS_OVERLAP&&t.union(n,a)}}for(var u={},l=0;l>1)*(this.N>>5)),a=0,i=this.getRandomOffsets_(t),o=0,c=0;c>1,i=n.length>>1,o=new Array(a),c=0;c>5;fn},tracking.Fast.isCorner=function(r,t,n){if(this.isTriviallyExcluded(t,r,n))return!1;for(var e=0;e<16;e++){for(var a=!0,i=!0,o=0;o<9;o++){var c=t[e+o&15];if(!this.isBrighter(r,c,n)&&(i=!1,a===!1))break;if(!this.isDarker(r,c,n)&&(a=!1,i===!1))break}if(i||a)return!0}return!1},tracking.Fast.isDarker=function(r,t,n){return t-r>n},tracking.Fast.isTriviallyExcluded=function(r,t,n){var e=0,a=r[8],i=r[12],o=r[4],c=r[0];return this.isBrighter(c,t,n)&&e++,this.isBrighter(o,t,n)&&e++,this.isBrighter(a,t,n)&&e++,this.isBrighter(i,t,n)&&e++,e<3&&(e=0,this.isDarker(c,t,n)&&e++,this.isDarker(o,t,n)&&e++,this.isDarker(a,t,n)&&e++,this.isDarker(i,t,n)&&e++,e<3)},tracking.Fast.getCircleOffsets_=function(r){if(this.circles_[r])return this.circles_[r];var t=new Int32Array(16);return t[0]=-r-r-r,t[1]=t[0]+1,t[2]=t[1]+r+1,t[3]=t[2]+r+1,t[4]=t[3]+r,t[5]=t[4]+r,t[6]=t[5]+r-1,t[7]=t[6]+r-1,t[8]=t[7]-1,t[9]=t[8]-1,t[10]=t[9]-r-1,t[11]=t[10]-r-1,t[12]=t[11]-r,t[13]=t[12]-r,t[14]=t[13]-r+1,t[15]=t[14]-r+1,this.circles_[r]=t,t}}(),function(){tracking.Math={},tracking.Math.distance=function(r,t,n,e){var a=n-r,i=e-t;return Math.sqrt(a*a+i*i)},tracking.Math.hammingWeight=function(r){return r-=r>>1&1431655765,r=(858993459&r)+(r>>2&858993459),16843009*(r+(r>>4)&252645135)>>24},tracking.Math.uniformRandom=function(r,t){return r+Math.random()*(t-r)},tracking.Math.intersectRect=function(r,t,n,e,a,i,o,c){return!(a>n||oe||cn&&(n=c),se&&(e=s)}return{width:n-a,height:e-i,x:a,y:i}},tracking.ColorTracker.prototype.getColors=function(){return this.colors},tracking.ColorTracker.prototype.getMinDimension=function(){return this.minDimension},tracking.ColorTracker.prototype.getMaxDimension=function(){return this.maxDimension},tracking.ColorTracker.prototype.getMinGroupSize=function(){return this.minGroupSize},tracking.ColorTracker.prototype.getNeighboursForWidth_=function(r){if(tracking.ColorTracker.neighbours_[r])return tracking.ColorTracker.neighbours_[r];var t=new Int32Array(8);return t[0]=4*-r,t[1]=4*-r+4,t[2]=4,t[3]=4*r+4,t[4]=4*r,t[5]=4*r-4,t[6]=-4,t[7]=4*-r-4,tracking.ColorTracker.neighbours_[r]=t,t},tracking.ColorTracker.prototype.mergeRectangles_=function(r){for(var t,n=[],e=this.getMinDimension(),a=this.getMaxDimension(),i=0;i=e&&o.height>=e&&o.width<=a&&o.height<=a&&n.push(o)}return n},tracking.ColorTracker.prototype.setColors=function(r){this.colors=r},tracking.ColorTracker.prototype.setMinDimension=function(r){this.minDimension=r},tracking.ColorTracker.prototype.setMaxDimension=function(r){this.maxDimension=r},tracking.ColorTracker.prototype.setMinGroupSize=function(r){this.minGroupSize=r},tracking.ColorTracker.prototype.track=function(r,t,n){var e=this,a=this.getColors();if(!a)throw new Error('Colors not specified, try `new tracking.ColorTracker("magenta")`.');var i=[];a.forEach(function(a){i=i.concat(e.trackColor_(r,t,n,a))}),this.emit("track",{data:i})},tracking.ColorTracker.prototype.trackColor_=function(n,e,a,i){var o,c,s,g,h,k=tracking.ColorTracker.knownColors_[i],f=new Int32Array(n.length>>2),u=new Int8Array(n.length),l=this.getMinGroupSize(),m=this.getNeighboursForWidth_(e),d=new Int32Array(n.length),v=[],p=-4;if(!k)return v;for(var y=0;y=0;)if(s=d[h--],c=d[h--],g=d[h--],k(n[g],n[g+1],n[g+2],n[g+3],g,c,s)){f[o++]=s,f[o++]=c;for(var T=0;T=0&&M=0&&_=l){var C=this.calculateDimensions_(f,o);C&&(C.color=i,v.push(C))}}return this.mergeRectangles_(v)},tracking.ColorTracker.registerColor("cyan",function(r,t,n){var e=50,a=70,i=r-0,o=t-255,c=n-255;return t-r>=e&&n-r>=a||i*i+o*o+c*c<6400}),tracking.ColorTracker.registerColor("magenta",function(r,t,n){var e=50,a=r-255,i=t-0,o=n-255;return r-t>=e&&n-t>=e||a*a+i*i+o*o<19600}),tracking.ColorTracker.registerColor("yellow",function(r,t,n){var e=50,a=r-255,i=t-255,o=n-0;return r-n>=e&&t-n>=e||a*a+i*i+o*o<1e4});var r=new Int32Array([-1,-1,0,1,1,1,0,-1]),t=new Int32Array([0,1,1,1,0,-1,-1,-1])}(),function(){tracking.ObjectTracker=function(r){tracking.ObjectTracker.base(this,"constructor"),r&&(Array.isArray(r)||(r=[r]),Array.isArray(r)&&r.forEach(function(t,n){if("string"==typeof t&&(r[n]=tracking.ViolaJones.classifiers[t]),!r[n])throw new Error('Object classifier not valid, try `new tracking.ObjectTracker("face")`.')})),this.setClassifiers(r)},tracking.inherits(tracking.ObjectTracker,tracking.Tracker),tracking.ObjectTracker.prototype.edgesDensity=.2,tracking.ObjectTracker.prototype.initialScale=1,tracking.ObjectTracker.prototype.scaleFactor=1.25,tracking.ObjectTracker.prototype.stepSize=1.5,tracking.ObjectTracker.prototype.getClassifiers=function(){return this.classifiers},tracking.ObjectTracker.prototype.getEdgesDensity=function(){return this.edgesDensity},tracking.ObjectTracker.prototype.getInitialScale=function(){return this.initialScale},tracking.ObjectTracker.prototype.getScaleFactor=function(){return this.scaleFactor},tracking.ObjectTracker.prototype.getStepSize=function(){return this.stepSize},tracking.ObjectTracker.prototype.track=function(r,t,n){var e=this,a=this.getClassifiers();if(!a)throw new Error('Object classifier not specified, try `new tracking.ObjectTracker("face")`.');var i=[];a.forEach(function(a){i=i.concat(tracking.ViolaJones.detect(r,t,n,e.getInitialScale(),e.getScaleFactor(),e.getStepSize(),e.getEdgesDensity(),a))}),this.emit("track",{data:i})},tracking.ObjectTracker.prototype.setClassifiers=function(r){this.classifiers=r},tracking.ObjectTracker.prototype.setEdgesDensity=function(r){this.edgesDensity=r},tracking.ObjectTracker.prototype.setInitialScale=function(r){this.initialScale=r},tracking.ObjectTracker.prototype.setScaleFactor=function(r){this.scaleFactor=r},tracking.ObjectTracker.prototype.setStepSize=function(r){this.stepSize=r}}(),function(){tracking.LandmarksTracker=function(){tracking.LandmarksTracker.base(this,"constructor")},tracking.inherits(tracking.LandmarksTracker,tracking.ObjectTracker),tracking.LandmarksTracker.prototype.track=function(r,t,n){var e=tracking.ViolaJones.classifiers.face,a=tracking.ViolaJones.detect(r,t,n,this.getInitialScale(),this.getScaleFactor(),this.getStepSize(),this.getEdgesDensity(),e),i=tracking.LBF.align(r,t,n,a);this.emit("track",{data:{faces:a,landmarks:i}})}}(),function(){tracking.LBF={},tracking.LBF.Regressor=function(r){this.maxNumStages=r,this.rfs=new Array(r),this.models=new Array(r);for(var t=0;t>2,i=e?new Uint32Array(a):new Uint8Array(a),o=new Uint32Array(r.buffer||new Uint8Array(r).buffer),c=0,s=0,g=0;if(e)for(;c>>16&255)+46871*(s>>>8&255)+4732*(255&s)>>>16,i[c++]=65793*g|4278190080&s;else for(;c>>16&255)+46871*(s>>>8&255)+4732*(255&s)>>>16,i[c++]=g;return new Uint8Array(i.buffer)},tracking.Image.horizontalConvolve=function(r,t,n,e,a){for(var i=e.length,o=Math.floor(i/2),c=new Float32Array(t*n*4),s=a?1:0,g=0;g0&&(s=new Int32Array(t*n)),tracking.Image.computeIntegralImage(r,t,n,k,f,u,s);for(var l=c[0],m=c[1],d=e*a,v=d*l|0,p=d*m|0;v0&&this.isTriviallyExcluded(o,s,w,T,t,v,p)||this.evalStages_(c,k,f,u,w,T,t,v,p,d)&&(h[g++]={width:v,height:p,x:T,y:w});d*=a,v=d*l|0,p=d*m|0}return this.mergeRectangles_(h)},tracking.ViolaJones.isTriviallyExcluded=function(r,t,n,e,a,i,o){var c=n*a+e,s=c+i,g=c+o*a,h=g+i,k=(t[c]-t[s]-t[g]+t[h])/(i*o*255);return k0&&(v=Math.sqrt(d));for(var p=r.length,y=2;y=this.REGIONS_OVERLAP&&h/(f*(k/f))>=this.REGIONS_OVERLAP&&t.union(n,a)}}for(var u={},l=0;l>1)*(this.N>>5)),a=0,i=this.getRandomOffsets_(t),o=0,c=0;c>1,i=n.length>>1,o=new Array(a),c=0;c>5;fn},tracking.Fast.isCorner=function(r,t,n){if(this.isTriviallyExcluded(t,r,n))return!1;for(var e=0;e<16;e++){for(var a=!0,i=!0,o=0;o<9;o++){var c=t[e+o&15];if(!this.isBrighter(r,c,n)&&(i=!1,a===!1))break;if(!this.isDarker(r,c,n)&&(a=!1,i===!1))break}if(i||a)return!0}return!1},tracking.Fast.isDarker=function(r,t,n){return t-r>n},tracking.Fast.isTriviallyExcluded=function(r,t,n){var e=0,a=r[8],i=r[12],o=r[4],c=r[0];return this.isBrighter(c,t,n)&&e++,this.isBrighter(o,t,n)&&e++,this.isBrighter(a,t,n)&&e++,this.isBrighter(i,t,n)&&e++,e<3&&(e=0,this.isDarker(c,t,n)&&e++,this.isDarker(o,t,n)&&e++,this.isDarker(a,t,n)&&e++,this.isDarker(i,t,n)&&e++,e<3)},tracking.Fast.getCircleOffsets_=function(r){if(this.circles_[r])return this.circles_[r];var t=new Int32Array(16);return t[0]=-r-r-r,t[1]=t[0]+1,t[2]=t[1]+r+1,t[3]=t[2]+r+1,t[4]=t[3]+r,t[5]=t[4]+r,t[6]=t[5]+r-1,t[7]=t[6]+r-1,t[8]=t[7]-1,t[9]=t[8]-1,t[10]=t[9]-r-1,t[11]=t[10]-r-1,t[12]=t[11]-r,t[13]=t[12]-r,t[14]=t[13]-r+1,t[15]=t[14]-r+1,this.circles_[r]=t,t}}(),function(){tracking.Math={},tracking.Math.distance=function(r,t,n,e){var a=n-r,i=e-t;return Math.sqrt(a*a+i*i)},tracking.Math.hammingWeight=function(r){return r-=r>>1&1431655765,r=(858993459&r)+(r>>2&858993459),16843009*(r+(r>>4)&252645135)>>24},tracking.Math.uniformRandom=function(r,t){return r+Math.random()*(t-r)},tracking.Math.intersectRect=function(r,t,n,e,a,i,o,c){return!(a>n||oe||cn&&(n=c),se&&(e=s)}return{width:n-a,height:e-i,x:a,y:i}},tracking.ColorTracker.prototype.getColors=function(){return this.colors},tracking.ColorTracker.prototype.getMinDimension=function(){return this.minDimension},tracking.ColorTracker.prototype.getMaxDimension=function(){return this.maxDimension},tracking.ColorTracker.prototype.getMinGroupSize=function(){return this.minGroupSize},tracking.ColorTracker.prototype.getNeighboursForWidth_=function(r){if(tracking.ColorTracker.neighbours_[r])return tracking.ColorTracker.neighbours_[r];var t=new Int32Array(8);return t[0]=4*-r,t[1]=4*-r+4,t[2]=4,t[3]=4*r+4,t[4]=4*r,t[5]=4*r-4,t[6]=-4,t[7]=4*-r-4,tracking.ColorTracker.neighbours_[r]=t,t},tracking.ColorTracker.prototype.mergeRectangles_=function(r){for(var t,n=[],e=this.getMinDimension(),a=this.getMaxDimension(),i=0;i=e&&o.height>=e&&o.width<=a&&o.height<=a&&n.push(o)}return n},tracking.ColorTracker.prototype.setColors=function(r){this.colors=r},tracking.ColorTracker.prototype.setMinDimension=function(r){this.minDimension=r},tracking.ColorTracker.prototype.setMaxDimension=function(r){this.maxDimension=r},tracking.ColorTracker.prototype.setMinGroupSize=function(r){this.minGroupSize=r},tracking.ColorTracker.prototype.track=function(r,t,n){var e=this,a=this.getColors();if(!a)throw new Error('Colors not specified, try `new tracking.ColorTracker("magenta")`.');var i=[];a.forEach(function(a){i=i.concat(e.trackColor_(r,t,n,a))}),this.emit("track",{data:i})},tracking.ColorTracker.prototype.trackColor_=function(n,e,a,i){var o,c,s,g,h,k=tracking.ColorTracker.knownColors_[i],f=new Int32Array(n.length>>2),u=new Int8Array(n.length),l=this.getMinGroupSize(),m=this.getNeighboursForWidth_(e),d=new Int32Array(n.length),v=[],p=-4;if(!k)return v;for(var y=0;y=0;)if(s=d[h--],c=d[h--],g=d[h--],k(n[g],n[g+1],n[g+2],n[g+3],g,c,s)){f[o++]=s,f[o++]=c;for(var T=0;T=0&&M=0&&_=l){var C=this.calculateDimensions_(f,o);C&&(C.color=i,v.push(C))}}return this.mergeRectangles_(v)},tracking.ColorTracker.registerColor("cyan",function(r,t,n){var e=50,a=70,i=r-0,o=t-255,c=n-255;return t-r>=e&&n-r>=a||i*i+o*o+c*c<6400}),tracking.ColorTracker.registerColor("magenta",function(r,t,n){var e=50,a=r-255,i=t-0,o=n-255;return r-t>=e&&n-t>=e||a*a+i*i+o*o<19600}),tracking.ColorTracker.registerColor("yellow",function(r,t,n){var e=50,a=r-255,i=t-255,o=n-0;return r-n>=e&&t-n>=e||a*a+i*i+o*o<1e4});var r=new Int32Array([-1,-1,0,1,1,1,0,-1]),t=new Int32Array([0,1,1,1,0,-1,-1,-1])}(),function(){tracking.ObjectTracker=function(r){tracking.ObjectTracker.base(this,"constructor"),r&&(Array.isArray(r)||(r=[r]),Array.isArray(r)&&r.forEach(function(t,n){if("string"==typeof t&&(r[n]=tracking.ViolaJones.classifiers[t]),!r[n])throw new Error('Object classifier not valid, try `new tracking.ObjectTracker("face")`.')})),this.setClassifiers(r)},tracking.inherits(tracking.ObjectTracker,tracking.Tracker),tracking.ObjectTracker.prototype.edgesDensity=.2,tracking.ObjectTracker.prototype.initialScale=1,tracking.ObjectTracker.prototype.scaleFactor=1.25,tracking.ObjectTracker.prototype.stepSize=1.5,tracking.ObjectTracker.prototype.getClassifiers=function(){return this.classifiers},tracking.ObjectTracker.prototype.getEdgesDensity=function(){return this.edgesDensity},tracking.ObjectTracker.prototype.getInitialScale=function(){return this.initialScale},tracking.ObjectTracker.prototype.getScaleFactor=function(){return this.scaleFactor},tracking.ObjectTracker.prototype.getStepSize=function(){return this.stepSize},tracking.ObjectTracker.prototype.track=function(r,t,n){var e=this,a=this.getClassifiers();if(!a)throw new Error('Object classifier not specified, try `new tracking.ObjectTracker("face")`.');var i=[];a.forEach(function(a){i=i.concat(tracking.ViolaJones.detect(r,t,n,e.getInitialScale(),e.getScaleFactor(),e.getStepSize(),e.getEdgesDensity(),a))}),this.emit("track",{data:i})},tracking.ObjectTracker.prototype.setClassifiers=function(r){this.classifiers=r},tracking.ObjectTracker.prototype.setEdgesDensity=function(r){this.edgesDensity=r},tracking.ObjectTracker.prototype.setInitialScale=function(r){this.initialScale=r},tracking.ObjectTracker.prototype.setScaleFactor=function(r){this.scaleFactor=r},tracking.ObjectTracker.prototype.setStepSize=function(r){this.stepSize=r}}(),function(){tracking.LandmarksTracker=function(){tracking.LandmarksTracker.base(this,"constructor")},tracking.inherits(tracking.LandmarksTracker,tracking.ObjectTracker),tracking.LandmarksTracker.prototype.track=function(r,t,n){var e=tracking.ViolaJones.classifiers.face,a=tracking.ViolaJones.detect(r,t,n,this.getInitialScale(),this.getScaleFactor(),this.getStepSize(),this.getEdgesDensity(),e),i=tracking.LBF.align(r,t,n,a);this.emit("track",{data:{faces:a,landmarks:i}})}}(),function(){tracking.LBF={},tracking.LBF.Regressor=function(r){this.maxNumStages=r,this.rfs=new Array(r),this.models=new Array(r);for(var t=0;t