-
Notifications
You must be signed in to change notification settings - Fork 0
/
show-face.html
90 lines (83 loc) · 2.88 KB
/
show-face.html
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Automatic Face Detection</title>
<style>
video, canvas {
display: block;
margin: 0 auto;
}
video, canvas {
max-width: 640px;
max-height: 480px;
}
canvas {
position: absolute;
top: 0;
left: 0;
pointer-events: none; /* Ensures that canvas does not capture mouse events */
}
#container {
position: relative;
}
#status {
position: absolute;
top: 10px;
left: 10px;
color: green;
font-size: 24px;
font-weight: bold;
}
</style>
</head>
<body>
<div id="container">
<video id="video" width="640" height="480" autoplay></video>
<canvas id="canvas" width="640" height="480"></canvas>
<div id="status">No Face Detected</div>
</div>
<script>
const video = document.getElementById('video');
const canvas = document.getElementById('canvas');
const context = canvas.getContext('2d');
const status = document.getElementById('status');
// Get access to the camera
if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
navigator.mediaDevices.getUserMedia({ video: true }).then(stream => {
video.srcObject = stream;
video.play();
});
}
video.addEventListener('play', () => {
const detectFace = () => {
if (video.paused || video.ended) return;
context.drawImage(video, 0, 0, canvas.width, canvas.height);
const dataURL = canvas.toDataURL('image/png');
fetch('http://localhost:5000/capture_face', {
method: 'POST',
body: JSON.stringify({ image: dataURL }),
headers: { 'Content-Type': 'application/json' }
})
.then(response => response.json())
.then(data => {
if (data.status === "success") {
status.textContent = "Face Detected";
status.style.color = "green";
location.href = 'log_in/log_img1.php';
} else {
status.textContent = "No Face Detected";
status.style.color = "red";
}
})
.catch(error => {
console.error('Error:', error);
});
setTimeout(detectFace, 500); // Adjust the interval as needed
};
detectFace();
});
</script>
</body>
</html>