const detectionOptions = {
video = createCapture(VIDEO);
video.size(width, height);
faceapi = ml5.faceApi(video, detectionOptions, modelReady);
faceapi.detect(gotResults);
function gotResults(err, result) {
image(video, 0, 0, width, height);
if (detections.length > 0) {
drawLandmarks(detections);
faceapi.detect(gotResults);
function drawBox(detections) {
for (let i = 0; i < detections.length; i += 1) {
const alignedRect = detections[i].alignedRect;
const x = alignedRect._box._x;
const y = alignedRect._box._y;
const boxWidth = alignedRect._box._width;
const boxHeight = alignedRect._box._height;
rect(x, y, boxWidth, boxHeight);
function drawLandmarks(detections) {
for (let i = 0; i < detections.length; i += 1) {
const mouth = detections[i].parts.mouth;
const nose = detections[i].parts.nose;
const leftEye = detections[i].parts.leftEye;
const rightEye = detections[i].parts.rightEye;
const rightEyeBrow = detections[i].parts.rightEyeBrow;
const leftEyeBrow = detections[i].parts.leftEyeBrow;
drawPart(leftEyeBrow, false);
drawPart(rightEye, true);
drawPart(rightEyeBrow, false);
function drawPart(feature, closed) {
for (let i = 0; i < feature.length; i += 1) {