-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
60 lines (51 loc) · 1.53 KB
/
Copy pathapp.js
File metadata and controls
60 lines (51 loc) · 1.53 KB
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
// check the media support
window.navigator.getUserMedia =
navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia;
// getting the elements
const audio = document.querySelector('#audio');
const video = document.querySelector('#video');
const canvas = document.querySelector('#canvas');
const loader = document.querySelector('#loeader');
// setting up the context for canvas => ( 2d or 3d );
const context = canvas.getContext('2d');
// loading the data model.
let model;
const modelParams = {
flipHorizontal: true, // flip e.g for video
imageScaleFactor: 0.7, // reduce input image size for gains in speed.
maxNumBoxes: 20, // maximum number of boxes to detect
iouThreshold: 0.5, // ioU threshold for non-max suppression
scoreThreshold: 0.79 // confidence threshold for predictions.
};
handTrack.load(modelParams).then(loadedModel => {
model = loadedModel;
loader.style.display = 'none';
});
// video settelment;
handTrack.startVideo(video).then(status => {
if (status) {
navigator.getUserMedia(
{ video: {} },
stream => {
video.srcObject = stream;
detector();
},
err => console.log(err)
);
}
});
// detector
const detector = () => {
model.detect(video).then(predictions => {
console.log(predictions);
//rendering the predicted model into dom.
model.renderPredictions(predictions, canvas, context, video);
if (predictions.length > 0) {
audio.play();
}
requestAnimationFrame(detector);
});
};