Skip to content

Commit

Permalink
minor restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
yofreke committed Sep 12, 2016
1 parent f885f47 commit d6c7ec9
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 138 deletions.
32 changes: 16 additions & 16 deletions js/Tracker.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
// 3rd party libs
const numeric = require('numeric');
import numeric from 'numeric';

// libs
const mosseFilter = require('./mosse.js');
const mosseFilterResponses = require('./mossefilter.js');
const jsfeat_face = require('./jsfeat_detect.js');
const webglFilter = require('./svmfilter_webgl.js');
const svmFilter = require('./svmfilter_fft.js');
import mosseFilter from './utils/mosse.js';
import mosseFilterResponses from './utils/mosseFilterResponses.js';
import JsfeatFace from './jsfeat/JsfeatFace';
import webglFilter from './svmfilter_webgl.js';
import svmFilter from './svmfilter_fft.js';

// filters
const entire_face_filter = require('./filters/entire_face_filter.json');
const left_eye_filter = require('./filters/left_eye_filter.json');
const right_eye_filter = require('./filters/right_eye_filter.json');
const nose_filter = require('./filters/nose_filter.json');
import entire_face_filter from './filters/entire_face_filter.json';
import left_eye_filter from './filters/left_eye_filter.json';
import right_eye_filter from './filters/right_eye_filter.json';
import nose_filter from './filters/nose_filter.json';


import {
requestAnimFrame,
cancelRequestAnimFrame
// drawData
} from './canvasHelpers';
import { gpopt, gpopt2 } from './meanshift';
import procrustes from './procrustes';
} from './utils/canvasHelpers';
import { gpopt, gpopt2 } from './utils/meanshift';
import procrustes from './utils/procrustes';


const halfPI = Math.PI / 2;
Expand Down Expand Up @@ -392,7 +392,7 @@ export default class Tracker {
// do viola-jones on canvas to get initial guess, if we don't have any points
if (!this.gettingPosition) {
this.gettingPosition = true;
this._getInitialPosition(element, box, function (gi) {
this._getInitialPosition(element, box, (gi) => {
this.gettingPosition = false;
if (!gi) {
// send an event on no face found
Expand All @@ -406,7 +406,7 @@ export default class Tracker {
this.track(element, box, gi);
}

}.bind(this));
});
}
return;
} else {
Expand Down Expand Up @@ -993,7 +993,7 @@ export default class Tracker {
var cc = canvas.getContext('2d');
cc.drawImage(el, 0, 0, el.width, el.height);

var jf = new jsfeat_face(canvas);
var jf = new JsfeatFace(canvas);
jf.faceDetected = this._faceDetected.bind(this);
//TODO Allow option that limit simultaneous trigger of WebWorkers
var comp = jf.findFace(callback);
Expand Down
3 changes: 0 additions & 3 deletions js/clm.js

This file was deleted.

4 changes: 2 additions & 2 deletions js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

var clm = require('./clm.js');
import Tracker from './Tracker';

module.exports = clm;
export { Tracker as tracker };
63 changes: 63 additions & 0 deletions js/jsfeat/JsfeatFace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// simple wrapper for jsfeat face detector
import findFaceWorker from './findFace.worker';

/**
* this cascade is derived from https://github.com/mtschirs/js-objectdetect implementation
* @author Martin Tschirsich / http://www.tu-darmstadt.de/~m_t
*/
import frontalface from '../filters/frontalface.json';

export default class JsfeatFace {
/**
* @param {Canvas|Image|Video} image
*/
constructor (image) {
this.work_canvas = undefined;
this.work_ctx = undefined;

this.image = image;
this.w = this.image.width;
this.h = this.image.height;

if (this.image.tagName == 'VIDEO' || this.image.tagName == 'IMG') {
this.work_canvas = document.createElement('canvas');
this.work_canvas.height = h;
this.work_canvas.width = w;
this.work_ctx = this.work_canvas.getContext('2d');
} else if (this.image.tagName == 'CANVAS') {
this.work_ctx = this.image.getContext('2d');
}

// img_u8 = new jsfeat.matrix_t(w, h, jsfeat.U8_t | jsfeat.C1_t);
// ii_sum = new Int32Array((w+1)*(h+1));
// ii_sqsum = new Int32Array((w+1)*(h+1));
// ii_tilted = new Int32Array((w+1)*(h+1));

// var classifier = frontalface;

this.worker = findFaceWorker();
}

findFace (callback) {
this.worker.addEventListener('message', (e) => {
if (e.data.type === 'console') {
console[e.data.func].apply(window, e.data.args);
return;
}

this.faceDetected(e, callback);
}, false);

if (this.image.tagName == 'VIDEO' || this.image.tagName == 'IMG') {
this.work_ctx.drawImage(this.image, 0, 0);
}
const imageData = this.work_ctx.getImageData(0, 0, this.w, this.h);

this.worker.postMessage({
w: this.w,
h: this.h,
imageData: imageData
});
}

}
58 changes: 58 additions & 0 deletions js/jsfeat/findFace.worker.js

Large diffs are not rendered by default.

59 changes: 0 additions & 59 deletions js/jsfeat_detect.js

This file was deleted.

58 changes: 0 additions & 58 deletions js/jsfeat_detect.worker.js

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit d6c7ec9

Please sign in to comment.