-
Notifications
You must be signed in to change notification settings - Fork 36
/
index.js
32 lines (29 loc) · 968 Bytes
/
index.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
import {Heartbeat} from './heartbeat.js';
const OPENCV_URI = "https://docs.opencv.org/master/opencv.js";
const HAARCASCADE_URI = "haarcascade_frontalface_alt.xml"
// Load opencv when needed
async function loadOpenCv(uri) {
return new Promise(function(resolve, reject) {
console.log("starting to load opencv");
var tag = document.createElement('script');
tag.src = uri;
tag.async = true;
tag.type = 'text/javascript'
tag.onload = () => {
cv['onRuntimeInitialized'] = () => {
console.log("opencv ready");
resolve();
}
};
tag.onerror = () => {
throw new URIError("opencv didn't load correctly.");
};
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
});
}
let demo = new Heartbeat("webcam", "canvas", HAARCASCADE_URI, 30, 6, 250);
var ready = loadOpenCv(OPENCV_URI);
ready.then(function() {
demo.init();
});