-
Notifications
You must be signed in to change notification settings - Fork 0
/
landmark_denotion.js
68 lines (65 loc) · 1.91 KB
/
landmark_denotion.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
64
65
66
67
68
const videoElement = document.getElementsByClassName("input_video")[0];
const canvasElement = document.getElementsByClassName("output_canvas")[0];
const canvasCtx = canvasElement.getContext("2d");
function onResults(results) {
canvasCtx.save();
canvasCtx.clearRect(0, 0, canvasElement.width, canvasElement.height);
canvasCtx.drawImage(
results.image,
0,
0,
canvasElement.width,
canvasElement.height
);
if (results.multiFaceLandmarks) {
for (const landmarks of results.multiFaceLandmarks) {
drawConnectors(canvasCtx, landmarks, FACEMESH_TESSELATION, {
color: "#C0C0C070",
lineWidth: 1,
});
drawConnectors(canvasCtx, landmarks, FACEMESH_RIGHT_EYE, {
color: "#FF3030",
});
drawConnectors(canvasCtx, landmarks, FACEMESH_RIGHT_EYEBROW, {
color: "#FF3030",
});
drawConnectors(canvasCtx, landmarks, FACEMESH_RIGHT_IRIS, {
color: "#FF3030",
});
drawConnectors(canvasCtx, landmarks, FACEMESH_LEFT_EYE, {
color: "#30FF30",
});
drawConnectors(canvasCtx, landmarks, FACEMESH_LEFT_EYEBROW, {
color: "#30FF30",
});
drawConnectors(canvasCtx, landmarks, FACEMESH_LEFT_IRIS, {
color: "#30FF30",
});
drawConnectors(canvasCtx, landmarks, FACEMESH_FACE_OVAL, {
color: "#E0E0E0",
});
drawConnectors(canvasCtx, landmarks, FACEMESH_LIPS, { color: "#E0E0E0" });
}
}
canvasCtx.restore();
}
const faceMesh = new FaceMesh({
locateFile: (file) => {
return `https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh/${file}`;
},
});
faceMesh.setOptions({
maxNumFaces: 1,
refineLandmarks: true,
minDetectionConfidence: 0.5,
minTrackingConfidence: 0.5,
});
faceMesh.onResults(onResults);
const camera = new Camera(videoElement, {
onFrame: async () => {
await faceMesh.send({ image: videoElement });
},
width: 1280,
height: 720,
});
camera.start();