xxxxxxxxxx
74
let capture;
let tracker;
let classifier;
let w, h;
let positions, parameters, emotion;
function setup() {
w = 1280;
h = 720;
capture = createCapture({
audio: false,
video: {
width: w,
height: h
}
}, function () {
console.log('capture ready.')
});
//capture.elt.setAttribute('playsinline', '');
createCanvas(windowWidth, windowHeight);
capture.size(w, h);
capture.hide();
tracker = new clm.tracker();
tracker.init();
tracker.start(capture.elt);
classifier = new emotionClassifier();
classifier.init(emotionModel);
}
function draw() {
background(0);
let zoomScale = windowWidth / 1280;
push();
scale(zoomScale, zoomScale);
image(capture, 0, 0, w, h);
drawLandmarkPoint();
pop();
positions = tracker.getCurrentPosition();
parameters = tracker.getCurrentParameters();
emotion = classifier.meanPredict(parameters);
drawEmotionGraph();
}
function drawLandmarkPoint() {
var positions = tracker.getCurrentPosition();
noStroke();
for (var i = 0; i < positions.length; i++) {
fill(0, 255, 0);
ellipse(positions[i][0], positions[i][1], 4, 4);
//text(i, positions[i][0], positions[i][1]);
}
}
function drawEmotionGraph() {
textSize(10);
push();
translate(10, 10);
for (let i = 0; i < emotion.length; i++) {
let len = map(emotion[i].value, 0, 1, 0, 200);
fill(255, 255, 0);
noStroke();
rect(80, 0, len, 5);
text(emotion[i].emotion, 0, 5);
translate(0, 10);
}
pop();
}