forked from jeeliz/jeelizFaceFilter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.js
67 lines (57 loc) · 2 KB
/
demo.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
61
62
63
64
65
66
67
"use strict";
let THREECAMERA = null;
// callback: launched if a face is detected or lost.
function detect_callback(faceIndex, isDetected) {
if (isDetected) {
console.log('INFO in detect_callback(): DETECTED');
} else {
console.log('INFO in detect_callback(): LOST');
}
}
// build the 3D. called once when Jeeliz Face Filter is OK
function init_threeScene(spec) {
const threeStuffs = JeelizThreeHelper.init(spec, detect_callback);
// CREATE A CUBE:
const cubeGeometry = new THREE.BoxGeometry(1,1,1);
const cubeMaterial = new THREE.MeshNormalMaterial();
const threeCube = new THREE.Mesh(cubeGeometry, cubeMaterial);
threeCube.frustumCulled = false;
threeStuffs.faceObject.add(threeCube);
// CREATE THE CAMERA:
const aspectRatio = spec.canvasElement.width / spec.canvasElement.height;
THREECAMERA=new THREE.PerspectiveCamera(20, aspectRatio, 0.1, 100);
} // end init_threeScene()
// entry point:
function main(){
JeelizResizer.size_canvas({
canvasId: 'jeeFaceFilterCanvas',
callback: function(isError, bestVideoSettings){
init_faceFilter(bestVideoSettings);
}
})
} //end main()
function init_faceFilter(videoSettings){
JEEFACEFILTERAPI.init({
canvasId: 'jeeFaceFilterCanvas',
NNCpath: '../../../dist/NNCwideAngles.json', // Neuron net with wide angles
maxFacesDetected: 1,
stabilizationSettings: { // adjust stabilization parameters for more responsivity
'translationFactorRange': [0.001, 0.003],
'rotationFactorRange': [0.002, 0.015],
'qualityFactorRange': [0.91, 0.98],
'alphaRange': [0.07, 1]
},
callbackReady: function(errCode, spec){
if (errCode){
console.log('AN ERROR HAPPENS. ERR =', errCode);
return;
}
console.log('INFO : JEEFACEFILTERAPI IS READY');
init_threeScene(spec);
},
//c alled at each render iteration (drawing loop):
callbackTrack: function(detectState){
JeelizThreeHelper.render(detectState, THREECAMERA);
}
}); //end JEEFACEFILTERAPI.init call
}