-
Notifications
You must be signed in to change notification settings - Fork 0
/
heart.js
32 lines (29 loc) · 962 Bytes
/
heart.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')
const 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.')
}
const firstScriptTag = document.getElementsByTagName('script')[0]
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag)
})
}
const demo = new Heartbeat('webcam', 'canvas', HAARCASCADE_URI, 30, 6, 250)
const ready = loadOpenCv(OPENCV_URI)
ready.then(function () {
demo.init()
})