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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Smart Home Security - Face Recognition</title>
|
7 |
+
<script src="https://cdn.jsdelivr.net/npm/face-api.js"></script>
|
8 |
+
<style>
|
9 |
+
:root {
|
10 |
+
--primary: #2962ff;
|
11 |
+
--dark: #1a237e;
|
12 |
+
--light: #f5f5f5;
|
13 |
+
--success: #00c853;
|
14 |
+
--danger: #d50000;
|
15 |
+
}
|
16 |
+
|
17 |
+
* {
|
18 |
+
margin: 0;
|
19 |
+
padding: 0;
|
20 |
+
box-sizing: border-box;
|
21 |
+
font-family: 'Segoe UI', sans-serif;
|
22 |
+
}
|
23 |
+
|
24 |
+
body {
|
25 |
+
background: var(--light);
|
26 |
+
min-height: 100vh;
|
27 |
+
}
|
28 |
+
|
29 |
+
.container {
|
30 |
+
max-width: 1200px;
|
31 |
+
margin: 0 auto;
|
32 |
+
padding: 20px;
|
33 |
+
}
|
34 |
+
|
35 |
+
.header {
|
36 |
+
background: var(--dark);
|
37 |
+
color: white;
|
38 |
+
padding: 1rem;
|
39 |
+
border-radius: 10px;
|
40 |
+
margin-bottom: 2rem;
|
41 |
+
display: flex;
|
42 |
+
justify-content: space-between;
|
43 |
+
align-items: center;
|
44 |
+
}
|
45 |
+
|
46 |
+
.main-content {
|
47 |
+
display: grid;
|
48 |
+
grid-template-columns: 2fr 1fr;
|
49 |
+
gap: 2rem;
|
50 |
+
}
|
51 |
+
|
52 |
+
.video-container {
|
53 |
+
background: white;
|
54 |
+
padding: 20px;
|
55 |
+
border-radius: 10px;
|
56 |
+
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
|
57 |
+
}
|
58 |
+
|
59 |
+
#video {
|
60 |
+
width: 100%;
|
61 |
+
border-radius: 5px;
|
62 |
+
}
|
63 |
+
|
64 |
+
.controls {
|
65 |
+
background: white;
|
66 |
+
padding: 20px;
|
67 |
+
border-radius: 10px;
|
68 |
+
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
|
69 |
+
}
|
70 |
+
|
71 |
+
.status {
|
72 |
+
text-align: center;
|
73 |
+
padding: 1rem;
|
74 |
+
margin: 1rem 0;
|
75 |
+
border-radius: 5px;
|
76 |
+
font-weight: bold;
|
77 |
+
}
|
78 |
+
|
79 |
+
.status.authorized {
|
80 |
+
background: var(--success);
|
81 |
+
color: white;
|
82 |
+
}
|
83 |
+
|
84 |
+
.status.unauthorized {
|
85 |
+
background: var(--danger);
|
86 |
+
color: white;
|
87 |
+
}
|
88 |
+
|
89 |
+
.btn {
|
90 |
+
background: var(--primary);
|
91 |
+
color: white;
|
92 |
+
border: none;
|
93 |
+
padding: 10px 20px;
|
94 |
+
border-radius: 5px;
|
95 |
+
cursor: pointer;
|
96 |
+
transition: 0.3s;
|
97 |
+
width: 100%;
|
98 |
+
margin: 5px 0;
|
99 |
+
}
|
100 |
+
|
101 |
+
.btn:hover {
|
102 |
+
background: var(--dark);
|
103 |
+
}
|
104 |
+
|
105 |
+
.registered-faces {
|
106 |
+
margin-top: 2rem;
|
107 |
+
}
|
108 |
+
|
109 |
+
.face-item {
|
110 |
+
display: flex;
|
111 |
+
align-items: center;
|
112 |
+
padding: 10px;
|
113 |
+
background: #f8f9fa;
|
114 |
+
margin: 5px 0;
|
115 |
+
border-radius: 5px;
|
116 |
+
}
|
117 |
+
|
118 |
+
.face-item img {
|
119 |
+
width: 50px;
|
120 |
+
height: 50px;
|
121 |
+
border-radius: 50%;
|
122 |
+
margin-right: 10px;
|
123 |
+
}
|
124 |
+
|
125 |
+
.loading {
|
126 |
+
position: fixed;
|
127 |
+
top: 0;
|
128 |
+
left: 0;
|
129 |
+
right: 0;
|
130 |
+
bottom: 0;
|
131 |
+
background: rgba(0,0,0,0.8);
|
132 |
+
display: flex;
|
133 |
+
justify-content: center;
|
134 |
+
align-items: center;
|
135 |
+
color: white;
|
136 |
+
font-size: 1.2rem;
|
137 |
+
}
|
138 |
+
|
139 |
+
@keyframes spin {
|
140 |
+
to { transform: rotate(360deg); }
|
141 |
+
}
|
142 |
+
|
143 |
+
.spinner {
|
144 |
+
width: 40px;
|
145 |
+
height: 40px;
|
146 |
+
border: 4px solid #f3f3f3;
|
147 |
+
border-top: 4px solid var(--primary);
|
148 |
+
border-radius: 50%;
|
149 |
+
animation: spin 1s linear infinite;
|
150 |
+
margin-right: 10px;
|
151 |
+
}
|
152 |
+
</style>
|
153 |
+
</head>
|
154 |
+
<body>
|
155 |
+
<div class="container">
|
156 |
+
<div class="header">
|
157 |
+
<h1>🏠 Smart Home Security</h1>
|
158 |
+
<div>System Status: <span id="system-status">Active</span></div>
|
159 |
+
</div>
|
160 |
+
|
161 |
+
<div class="main-content">
|
162 |
+
<div class="video-container">
|
163 |
+
<video id="video" autoplay muted></video>
|
164 |
+
<div class="status" id="access-status">Waiting for face detection...</div>
|
165 |
+
</div>
|
166 |
+
|
167 |
+
<div class="controls">
|
168 |
+
<h2>Control Panel</h2>
|
169 |
+
<button class="btn" id="add-face">Add New Face</button>
|
170 |
+
<button class="btn" id="test-detection">Test Detection</button>
|
171 |
+
|
172 |
+
<div class="registered-faces">
|
173 |
+
<h3>Registered Users</h3>
|
174 |
+
<div id="faces-list">
|
175 |
+
<!-- Registered faces will be listed here -->
|
176 |
+
</div>
|
177 |
+
</div>
|
178 |
+
</div>
|
179 |
+
</div>
|
180 |
+
</div>
|
181 |
+
|
182 |
+
<div class="loading" id="loading" style="display: none;">
|
183 |
+
<div class="spinner"></div>
|
184 |
+
Loading face detection models...
|
185 |
+
</div>
|
186 |
+
|
187 |
+
<script>
|
188 |
+
// Mock database of registered faces
|
189 |
+
const registeredFaces = [
|
190 |
+
{ id: 1, name: 'John Doe', image: 'data:image/jpeg;base64,/9j/4AAQSkZJRg==' },
|
191 |
+
{ id: 2, name: 'Jane Smith', image: 'data:image/jpeg;base64,/9j/4AAQSkZJRg==' }
|
192 |
+
];
|
193 |
+
|
194 |
+
// Initialize face detection
|
195 |
+
async function initFaceDetection() {
|
196 |
+
try {
|
197 |
+
document.getElementById('loading').style.display = 'flex';
|
198 |
+
|
199 |
+
// Load face-api models (in real implementation)
|
200 |
+
// await faceapi.nets.tinyFaceDetector.loadFromUri('/models');
|
201 |
+
// await faceapi.nets.faceLandmark68Net.loadFromUri('/models');
|
202 |
+
// await faceapi.nets.faceRecognitionNet.loadFromUri('/models');
|
203 |
+
|
204 |
+
// Access webcam
|
205 |
+
const video = document.getElementById('video');
|
206 |
+
const stream = await navigator.mediaDevices.getUserMedia({ video: true });
|
207 |
+
video.srcObject = stream;
|
208 |
+
|
209 |
+
document.getElementById('loading').style.display = 'none';
|
210 |
+
} catch (error) {
|
211 |
+
console.error('Error initializing face detection:', error);
|
212 |
+
document.getElementById('loading').style.display = 'none';
|
213 |
+
}
|
214 |
+
}
|
215 |
+
|
216 |
+
// Simulate face detection
|
217 |
+
function detectFace() {
|
218 |
+
const accessStatus = document.getElementById('access-status');
|
219 |
+
const isAuthorized = Math.random() > 0.5; // Simulate detection
|
220 |
+
|
221 |
+
if (isAuthorized) {
|
222 |
+
accessStatus.textContent = 'Access Granted ✅';
|
223 |
+
accessStatus.className = 'status authorized';
|
224 |
+
} else {
|
225 |
+
accessStatus.textContent = 'Access Denied ❌';
|
226 |
+
accessStatus.className = 'status unauthorized';
|
227 |
+
}
|
228 |
+
}
|
229 |
+
|
230 |
+
// Display registered faces
|
231 |
+
function displayRegisteredFaces() {
|
232 |
+
const facesList = document.getElementById('faces-list');
|
233 |
+
facesList.innerHTML = registeredFaces.map(face => `
|
234 |
+
<div class="face-item">
|
235 |
+
<img src="${face.image}" alt="${face.name}">
|
236 |
+
<div>
|
237 |
+
<h4>${face.name}</h4>
|
238 |
+
<small>ID: ${face.id}</small>
|
239 |
+
</div>
|
240 |
+
</div>
|
241 |
+
`).join('');
|
242 |
+
}
|
243 |
+
|
244 |
+
// Event listeners
|
245 |
+
document.getElementById('add-face').addEventListener('click', () => {
|
246 |
+
const name = prompt('Enter name for new face:');
|
247 |
+
if (name) {
|
248 |
+
registeredFaces.push({
|
249 |
+
id: registeredFaces.length + 1,
|
250 |
+
name,
|
251 |
+
image: 'data:image/jpeg;base64,/9j/4AAQSkZJRg=='
|
252 |
+
});
|
253 |
+
displayRegisteredFaces();
|
254 |
+
}
|
255 |
+
});
|
256 |
+
|
257 |
+
document.getElementById('test-detection').addEventListener('click', detectFace);
|
258 |
+
|
259 |
+
// Initialize application
|
260 |
+
window.addEventListener('load', () => {
|
261 |
+
initFaceDetection();
|
262 |
+
displayRegisteredFaces();
|
263 |
+
});
|
264 |
+
</script>
|
265 |
+
</body>
|
266 |
+
</html>
|