-
Notifications
You must be signed in to change notification settings - Fork 537
/
Copy pathmain.js
60 lines (48 loc) · 1.66 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
52
53
54
55
56
57
58
59
60
function main(){ // entry point
const videoElement = document.getElementById('myVideo');
if (videoElement['currentTime'] && videoElement['videoWidth'] && videoElement['videoHeight']){
start_videoFile(videoElement);
start_camera();
} else {
setTimeout(main, 100);
videoElement['play']();
}
}
function start_videoFile(videoElement){
start(JEELIZFACEFILTER, 'jeeFaceFilterCanvas', videoElement, 'yellow');
}
function start_camera(){
const JEELIZFACEFILTER2 = JEELIZFACEFILTER.create_new();
start(JEELIZFACEFILTER2, 'jeeFaceFilterCanvas2', null, 'lime');
}
function start(jeeFaceFilterAPIInstance, canvasId, videoElement, borderColor){
let cvd = null; // return of Canvas2DDisplay
jeeFaceFilterAPIInstance.init({
canvasId: canvasId,
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 = borderColor;
},
// 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();
}
});
}
window.addEventListener('load', main);