-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathindex.html
More file actions
54 lines (49 loc) · 1.91 KB
/
Copy pathindex.html
File metadata and controls
54 lines (49 loc) · 1.91 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
canvas,
video {
position: absolute;
left: 0;
top: 0;
}
</style>
</head>
<body onload="init()">
<video id="video" width="720" height="480" autoplay muted>
<script src="face-api.min.js"></script>
<script>
async function init() {
await faceapi.nets.tinyFaceDetector.loadFromUri('/models');
await faceapi.nets.faceLandmark68Net.loadFromUri('/models');
await faceapi.nets.faceRecognitionNet.loadFromUri('/models');
await faceapi.nets.faceExpressionNet.loadFromUri('/models');
navigator.getUserMedia({
video: {}
},
s => video.srcObject = s,
console.error);
}
video.addEventListener('play', startFaceDetection)
function startFaceDetection(){
let canvas = faceapi.createCanvasFromMedia(video);
document.body.append(canvas);
setInterval(async function(){
let options = new faceapi.TinyFaceDetectorOptions();
canvas.getContext('2d').clearRect(0, 0, canvas.width, canvas.height);
let size = {width: video.width, height: video.height};
let detections = await faceapi.detectAllFaces(video, options).withFaceLandmarks().withFaceExpressions();
let resizedDetections = faceapi.resizeResults(detections, size);
faceapi.draw.drawDetections(canvas, resizedDetections);
faceapi.draw.drawFaceLandmarks(canvas, resizedDetections);
faceapi.draw.drawFaceExpressions(canvas, resizedDetections);
}, 100);
}
</script>
</body>
</html>