-
Notifications
You must be signed in to change notification settings - Fork 536
/
main.js
51 lines (41 loc) · 1.38 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
let VIDEOELEMENT = null;
function main(){ // entry point
VIDEOELEMENT = document.getElementById('myVideo');
if (VIDEOELEMENT['currentTime'] && VIDEOELEMENT['videoWidth'] && VIDEOELEMENT['videoHeight']){
start();
} else {
setTimeout(main, 100);
VIDEOELEMENT['play']();
}
}
function start(){ // launched when the video is loaded
let CVD = null; // return of Canvas2DDisplay
JEELIZFACEFILTER.init({
canvasId: 'jeeFaceFilterCanvas',
videoSettings: {
videoElement: VIDEOELEMENT
},
NNCPath: '../../../neuralNets/', // root of NN_DEFAULT.json file
callbackReady: function(errCode, spec){
if (errCode){
console.log('AN ERROR HAPPENS. SORRY BRO :( . ERR =', errCode);
return;
}
console.log('INFO: JEELIZFACEFILTER IS READY');
CVD = JeelizCanvas2DHelper(spec);
CVD.ctx.strokeStyle = 'yellow';
},
// called at each render iteration (drawing loop):
callbackTrack: function(detectState){
if (detectState.detected>0.6){
// draw a border around the face:
const faceCoo = CVD.getCoordinates(detectState);
CVD.ctx.clearRect(0,0,CVD.canvas.width, CVD.canvas.height);
CVD.ctx.strokeRect(faceCoo.x, faceCoo.y, faceCoo.w, faceCoo.h);
CVD.update_canvasTexture();
}
CVD.draw();
}
}); //end JEELIZFACEFILTER.init call
}
window.addEventListener('load', main);