-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathHTML_interface.html
242 lines (234 loc) · 5.79 KB
/
HTML_interface.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Face Recognition Access Control</title>
<style>
@media only screen and (min-width: 850px) {
body {
display: flex;
}
#content-right {
margin-left: 10px;
}
}
body {
font-family: Arial, Helvetica, sans-serif;
background: #181818;
color: #EFEFEF;
font-size: 16px;
}
#content-left {
max-width: 400px;
flex: 1;
}
#content-right {
max-width: 400px;
flex: 1;
}
#stream {
width: 100%;
}
#status-display {
height: 25px;
border: none;
padding: 10px;
font: 18px/22px sans-serif;
margin-bottom: 10px;
border-radius: 5px;
background: green;
text-align: center;
}
#person {
width:100%;
height: 25px;
border: none;
padding: 20px 10px;
font: 18px/22px sans-serif;
margin-bottom: 10px;
border-radius: 5px;
resize: none;
box-sizing: border-box;
}
button {
display: block;
margin: 5px 0;
padding: 0 12px;
border: 0;
width: 48%;
line-height: 28px;
cursor: pointer;
color: #fff;
background: #ff3034;
border-radius: 5px;
font-size: 16px;
outline: 0;
}
.buttons {
height:40px;
}
button:hover {
background: #ff494d;
}
button:active {
background: #f21c21;
}
button:disabled {
cursor: default;
background: #a0a0a0;
}
.left {
float: left;
}
.right {
float: right;
}
.image-container {
position: relative;
}
.stream {
max-width: 400px;
}
ul {
list-style: none;
padding: 5px;
margin:0;
}
li {
padding: 5px 0;
}
.delete {
background: #ff3034;
border-radius: 100px;
color: #fff;
text-align: center;
line-height: 18px;
cursor: pointer;
}
h3 {
margin-bottom: 3px;
}
</style>
</head>
<body>
<div id="content-left">
<div id="stream-container" class="image-container"> <img id="stream" src=""> </div>
</div>
<div id="content-right">
<div id="status-display"> <span id="current-status"></span> </div>
<div id="person-name">
<input id="person" type="text" value="" placeholder="Type the person's name here">
</div>
<div class="buttons">
<button id="button-stream" class="left">STREAM CAMERA</button>
<button id="button-detect" class="right">DETECT FACES</button>
</div>
<div class="buttons">
<button id="button-capture" class="left" title="Enter a name above before capturing a face">ADD USER</button>
<button id="button-recognise" class="right">ACCESS CONTROL</button>
</div>
<div class="people">
<h3>Captured Faces</h3>
<ul>
</ul>
</div>
<div class="buttons">
<button id="delete_all">DELETE ALL</button>
</div>
</div>
<script>
document.addEventListener("DOMContentLoaded", function(event) {
var baseHost = document.location.origin;
var streamUrl = baseHost + ":81";
const WS_URL = "ws://" + window.location.host + ":82";
const ws = new WebSocket(WS_URL);
const view = document.getElementById("stream");
const personFormField = document.getElementById("person");
const streamButton = document.getElementById("button-stream");
const detectButton = document.getElementById("button-detect");
const captureButton = document.getElementById("button-capture");
const recogniseButton = document.getElementById("button-recognise");
const deleteAllButton = document.getElementById("delete_all");
// gain, frequency, duration
a=new AudioContext();
function alertSound(w,x,y){
v=a.createOscillator();
u=a.createGain();
v.connect(u);
v.frequency.value=x;
v.type="square";
u.connect(a.destination);
u.gain.value=w*0.01;
v.start(a.currentTime);
v.stop(a.currentTime+y*0.001);
}
ws.onopen = () => {
console.log(`Connected to ${WS_URL}`);
};
ws.onmessage = message => {
if (typeof message.data === "string") {
if (message.data.substr(0, 8) == "listface") {
addFaceToScreen(message.data.substr(9));
} else if (message.data == "delete_faces") {
deleteAllFacesFromScreen();
} else if (message.data == "door_open") {
alertSound(10,233,100); alertSound(3,603,200);
} else {
document.getElementById("current-status").innerHTML = message.data;
document.getElementById("status-display").style.background = "green";
}
}
if (message.data instanceof Blob) {
var urlObject = URL.createObjectURL(message.data);
view.src = urlObject;
}
}
streamButton.onclick = () => {
ws.send("stream");
};
detectButton.onclick = () => {
ws.send("detect");
};
captureButton.onclick = () => {
person_name = document.getElementById("person").value;
ws.send("capture:" + person_name);
};
recogniseButton.onclick = () => {
ws.send("recognise");
};
deleteAllButton.onclick = () => {
ws.send("delete_all");
};
personFormField.onkeyup = () => {
captureButton.disabled = false;
};
function deleteAllFacesFromScreen() {
// deletes face list in browser only
const faceList = document.querySelector("ul");
while (faceList.firstChild) {
faceList.firstChild.remove();
}
personFormField.value = "";
captureButton.disabled = true;
}
function addFaceToScreen(person_name) {
const faceList = document.querySelector("ul");
let listItem = document.createElement("li");
let closeItem = document.createElement("span");
closeItem.classList.add("delete");
closeItem.id = person_name;
closeItem.addEventListener("click", function() {
ws.send("remove:" + person_name);
});
listItem.appendChild(
document.createElement("strong")
).textContent = person_name;
listItem.appendChild(closeItem).textContent = "X";
faceList.appendChild(listItem);
}
captureButton.disabled = true;
});
</script>
</body>
</html>