-
Notifications
You must be signed in to change notification settings - Fork 1
/
thumos.js
64 lines (56 loc) · 1.59 KB
/
thumos.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
const microevent = require('microevent')
const clm = require('clmtrackr')
const pModel = require('./model_pca_20_svm.json')
var raf = require('raf')
var Thumos = function (videoId, overlayId, drawModel, delta=500) {
var self = this
var video = document.getElementById(videoId)
var overlay = document.getElementById(overlayId)
if (drawModel) {
var overlayCC = overlay.getContext('2d')
}
var positions
var ctrack = new clm.tracker({useWebGL: true})
ctrack.init(pModel)
// start tracking
ctrack.start(video)
// start loop to draw face and obtain position data
update()
emit()
function emit () {
setInterval(function () {
var endPositions
var startTime
var endTime
var x_array = []
var y_array = []
startTime = new Date()
setTimeout(function deltas () {
endPositions = positions
if (endPositions && endPositions.length) {
endTime = new Date()
for (var i = 0; i < endPositions.length; i++) {
x_array.push(endPositions[i][0])
y_array.push(endPositions[i][1])
}
self.trigger('faceMoving',
{'time': new Date(),
'xArray': x_array,
'yArray': y_array})
}
}, delta)
}, delta)
}
function update () {
raf(update)
if (drawModel) {
overlayCC.clearRect(0, 0, video.videoWidth, video.videoHeight)
}
positions = ctrack.getCurrentPosition()
if (positions && drawModel) {
ctrack.draw(overlay)
}
}
}
microevent.mixin(Thumos)
module.exports = Thumos