Atualli commited on
Commit
5975e22
1 Parent(s): 951381e

Create testeface.html

Browse files
Files changed (1) hide show
  1. static/testeface.html +65 -0
static/testeface.html ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <script src="https://cdn.jsdelivr.net/npm/@mediapipe/camera_utils/camera_utils.js" crossorigin="anonymous"></script>
6
+ <script src="https://cdn.jsdelivr.net/npm/@mediapipe/control_utils/control_utils.js" crossorigin="anonymous"></script>
7
+ <script src="https://cdn.jsdelivr.net/npm/@mediapipe/drawing_utils/drawing_utils.js" crossorigin="anonymous"></script>
8
+ <script src="https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh/face_mesh.js" crossorigin="anonymous"></script>
9
+ </head>
10
+
11
+ <body>
12
+ <div class="container">
13
+ <video id="videoin"class="input_video"></video>
14
+ <canvas class="output_canvas" width="1280px" height="720px"></canvas>
15
+ </div>
16
+ <script type="module">
17
+ const videoElement = document.getElementsByClassName('input_video')[0];
18
+ const canvasElement = document.getElementsByClassName('output_canvas')[0];
19
+ const canvasCtx = canvasElement.getContext('2d');
20
+
21
+ function onResults(results) {
22
+ document.getElementById("videoin").style.display = "none";
23
+ canvasCtx.save();
24
+ canvasCtx.clearRect(0, 0, canvasElement.width, canvasElement.height);
25
+ canvasCtx.drawImage(
26
+ results.image, 0, 0, canvasElement.width, canvasElement.height);
27
+ if (results.multiFaceLandmarks) {
28
+ for (const landmarks of results.multiFaceLandmarks) {
29
+ drawConnectors(canvasCtx, landmarks, FACEMESH_TESSELATION,
30
+ {color: '#C0C0C070', lineWidth: 1});
31
+ drawConnectors(canvasCtx, landmarks, FACEMESH_RIGHT_EYE, {color: '#FF3030'});
32
+ drawConnectors(canvasCtx, landmarks, FACEMESH_RIGHT_EYEBROW, {color: '#FF3030'});
33
+ drawConnectors(canvasCtx, landmarks, FACEMESH_RIGHT_IRIS, {color: '#FF3030'});
34
+ drawConnectors(canvasCtx, landmarks, FACEMESH_LEFT_EYE, {color: '#30FF30'});
35
+ drawConnectors(canvasCtx, landmarks, FACEMESH_LEFT_EYEBROW, {color: '#30FF30'});
36
+ drawConnectors(canvasCtx, landmarks, FACEMESH_LEFT_IRIS, {color: '#30FF30'});
37
+ drawConnectors(canvasCtx, landmarks, FACEMESH_FACE_OVAL, {color: '#E0E0E0'});
38
+ drawConnectors(canvasCtx, landmarks, FACEMESH_LIPS, {color: '#E0E0E0'});
39
+ }
40
+ }
41
+ canvasCtx.restore();
42
+ }
43
+
44
+ const faceMesh = new FaceMesh({locateFile: (file) => {
45
+ return `https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh/${file}`;
46
+ }});
47
+ faceMesh.setOptions({
48
+ maxNumFaces: 10,
49
+ refineLandmarks: true,
50
+ minDetectionConfidence: 0.5,
51
+ minTrackingConfidence: 0.5
52
+ });
53
+ faceMesh.onResults(onResults);
54
+
55
+ const camera = new Camera(videoElement, {
56
+ onFrame: async () => {
57
+ await faceMesh.send({image: videoElement});
58
+ },
59
+ width: 1280,
60
+ height: 720
61
+ });
62
+ camera.start();
63
+ </script>
64
+ </body>
65
+ </html>