-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
258 lines (221 loc) · 16.3 KB
/
Copy pathindex.html
File metadata and controls
258 lines (221 loc) · 16.3 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
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Scholar Zolo - Night Attendance</title>
<script defer src="https://cdn.jsdelivr.net/npm/face-api.js@0.22.2/dist/face-api.min.js"></script>
<style>
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background-color: #121212; color: #ffffff; display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; margin: 0; overflow: hidden; }
#camera-wrapper { position: relative; width: 100%; max-width: 350px; aspect-ratio: 3/4; background-color: #222; border-radius: 20px; overflow: hidden; border: 3px solid #333; box-shadow: 0 10px 30px rgba(0,0,0,0.5); display: none; }
video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
canvas { position: absolute; top: 0; left: 0; transform: scaleX(-1); }
/* --- NEW DYNAMIC CARD DESIGN --- */
#student-card {
position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
width: 90%; max-width: 340px;
background: rgba(20, 20, 20, 0.98);
border: 2px solid #00ff88;
border-radius: 20px;
padding: 25px;
text-align: center;
display: none;
box-shadow: 0 0 50px rgba(0, 255, 136, 0.2);
z-index: 100;
}
/* Header Section (Fixed) */
.card-header { position: relative; margin-bottom: 20px; padding-bottom: 15px; border-bottom: 1px solid #333; }
#card-img { width: 90px; height: 90px; border-radius: 50%; border: 3px solid #00ff88; object-fit: cover; margin-bottom: 10px; }
#card-name { margin: 0; color: #00ff88; font-size: 24px; font-weight: 700; letter-spacing: 0.5px; }
#card-roll { margin: 2px 0; color: #aaa; font-size: 14px; letter-spacing: 1px; }
/* Time Badge (Top Right) */
.time-badge {
position: absolute; top: 0; right: 0;
background: #004422; color: #00ff88;
padding: 5px 10px; border-radius: 8px;
font-size: 11px; font-weight: bold;
border: 1px solid #00ff88;
box-shadow: 0 0 10px rgba(0,255,136,0.2);
}
/* THE DYNAMIC GRID (Automatic 3 Columns) */
#details-grid {
display: grid;
grid-template-columns: repeat(3, 1fr); /* Force 3 items per row */
gap: 10px;
text-align: center;
}
/* Individual Data Box */
.data-box { background: #2a2a2a; padding: 8px 5px; border-radius: 8px; }
.data-label { font-size: 9px; color: #888; text-transform: uppercase; margin-bottom: 3px; font-weight: 600; }
.data-value { font-size: 12px; color: white; font-weight: bold; word-wrap: break-word; }
button { background-color: #007aff; color: white; border: none; padding: 18px 40px; font-size: 18px; border-radius: 12px; cursor: pointer; font-weight: 600; margin-top: 20px; }
button:disabled { background-color: #444; color: #888; cursor: wait; }
#status { margin-top: 20px; font-size: 16px; font-weight: 500; min-height: 24px;}
.success { color: #00ff88; text-shadow: 0 0 10px rgba(0,255,136,0.3); }
.error { color: #ff4444; }
</style>
</head>
<body>
<h2 style="margin-bottom: 5px; font-weight: 800; letter-spacing: 1px;">Scholar Zolo</h2>
<p style="color:#00ff88; margin-top:0; font-size: 12px; font-family: monospace;">POWERED BY GFAS™</p>
<div id="camera-wrapper">
<video id="video" autoplay playsinline muted></video>
</div>
<div id="student-card">
<div class="card-header">
<div class="time-badge" id="card-time">--:-- AM</div> <img id="card-img" src="" alt="Student">
<h2 id="card-name">Student Name</h2>
<p id="card-roll">Roll No: --</p>
</div>
<div id="details-grid"></div>
<button onclick="location.reload()" style="background:#333; margin-top:20px; padding:10px 30px; font-size:14px; width:100%;">Close & Reset</button>
</div>
<button id="start-btn" onclick="initApp()">📍 Verify Identity</button>
<div id="status">Ready</div>
<script>
const STUDENT_DATABASE = {
"251580052142": {
name: "Sanskar Jaiswal",
descriptor: [-0.10651249438524246,0.18682342767715454,0.030025772750377655,0.0597865954041481,-0.03422766551375389,0.008696001954376698,-0.018361791968345642,-0.05388065055012703,0.1480509638786316,-0.07772717624902725,0.20302365720272064,-0.0489942841231823,-0.16818548738956451,-0.17404504120349884,0.04553290456533432,0.15252362191677094,-0.14591968059539795,-0.15702958405017853,-0.07042010128498077,-0.1297890543937683,-0.03127942979335785,0.03627530485391617,0.021350037306547165,0.024174416437745094,-0.13216930627822876,-0.39184117317199707,-0.04722302779555321,-0.213333398103714,0.08022776991128922,-0.12750685214996338,-0.11120283603668213,0.010999293997883797,-0.1709655523300171,-0.0692744255065918,0.04785255715250969,0.09364595264196396,-0.07404015958309174,0.012504657730460167,0.1660287231206894,0.08096040785312653,-0.09956599771976471,-0.017374319955706596,0.00833385530859232,0.35778000950813293,0.16125503182411194,0.07337914407253265,-0.018541021272540092,-0.008995099924504757,0.057226113975048065,-0.1453532725572586,0.10733113437891006,0.13188990950584412,0.16438676416873932,0.1115197166800499,0.07700592279434204,-0.16532081365585327,-0.0028583710081875324,-0.029965374618768692,-0.18230286240577698,0.035991471260786057,0.02863195724785328,-0.0558345653116703,-0.07593853026628494,0.010942112654447556,0.348543256521225,0.09120941907167435,-0.09081186354160309,-0.0747431293129921,0.1811356097459793,-0.10597250610589981,0.032200541347265244,0.04753363877534866,-0.09860517829656601,-0.13396196067333221,-0.18846814334392548,0.1410064846277237,0.45358631014823914,0.12140689045190811,-0.18467175960540771,-0.03920607268810272,-0.10799363255500793,-0.08673296868801117,0.038858894258737564,0.09900973737239838,-0.13344353437423706,0.012968548573553562,-0.03955121710896492,0.045274753123521805,0.12248621135950089,-0.030933544039726257,-0.05085388198494911,0.14642451703548431,-0.040817372500896454,0.03071160614490509,0.03887467831373215,-0.10176144540309906,-0.09837093204259872,-0.005263424012809992,-0.07781867682933807,-0.10289531201124191,0.03172345459461212,-0.17280079424381256,-0.022891027852892876,0.09636249393224716,-0.1927006095647812,0.09081775695085526,0.07299776375293732,-0.05545508489012718,0.014620764181017876,0.11170022189617157,-0.14487811923027039,-0.11120466887950897,0.14856559038162231,-0.27151331305503845,0.23440691828727722,0.1879683881998062,0.06657587736845016,0.17299717664718628,0.0542137585580349,0.09039709717035294,0.018023202195763588,-0.024208230897784233,-0.11325273662805557,-0.04293964058160782,0.07106306403875351,-0.0031580927316099405,0.020327458158135414,0.019016319885849953],
hostel: "HB-4",
wing: "C - Wing",
room: "1146",
branch: "CSE"
},
"251580050320": {
name: "Rudranath Gade",
descriptor: [-0.1669635772705078,0.05774740129709244,0.017321303486824036,-0.0521155409514904,0.035405680537223816,-0.09155944734811783,0.019700046628713608,-0.09570533037185669,0.14231464266777039,0.00808771699666977,0.22330351173877716,-0.033727701753377914,-0.18912218511104584,-0.13702622056007385,-0.013209481723606586,0.10625797510147095,-0.12394612282514572,-0.23293277621269226,-0.05778427794575691,-0.18888147175312042,-0.05940743535757065,-0.0028140610083937645,-0.0309064369648695,0.10229494422674179,-0.16015754640102386,-0.2538359463214874,-0.05115567520260811,-0.18427680432796478,-0.023131467401981354,-0.04464277997612953,-0.004197316709905863,0.09554758667945862,-0.179072767496109,-0.05843226611614227,0.058323994278907776,0.10379424691200256,0.025486692786216736,-0.002861947752535343,0.17771179974079132,0.05622703954577446,-0.07181894034147263,-0.05266664922237396,0.0613851323723793,0.3283996284008026,0.1422632336616516,0.0037447658833116293,-0.01904556341469288,0.027352474629878998,0.05569816008210182,-0.21325500309467316,0.04425659775733948,0.1458287388086319,0.11409754306077957,0.04114733263850212,0.09877128899097443,-0.1816447526216507,-0.01720966212451458,0.032963089644908905,-0.14561955630779266,0.04558660089969635,-0.0410555899143219,-0.04280120134353638,-0.10684089362621307,-0.08791612088680267,0.24295976758003235,0.12837323546409607,-0.11179733276367188,-0.08210264891386032,0.20669794082641602,-0.07438509911298752,-0.04560413584113121,0.07808651030063629,-0.11167862266302109,-0.1344982385635376,-0.20404215157032013,0.14036664366722107,0.3990231156349182,0.08030904829502106,-0.17669403553009033,0.051482245326042175,-0.07656833529472351,-0.026843450963497162,0.0014135671081021428,-0.03837216645479202,-0.15265215933322906,0.05450043827295303,-0.09980590641498566,-0.0064082276076078415,0.13926905393600464,0.07902514934539795,-0.06034572422504425,0.1119740754365921,-0.10108332335948944,0.03610646724700928,0.08909390866756439,0.015318863093852997,-0.05933666229248047,0.014949454925954342,-0.14521069824695587,-0.043524082750082016,0.0841328352689743,-0.1136753112077713,-0.0010728080524131656,0.08092141896486282,-0.14582285284996033,0.019371774047613144,0.04013310745358467,-0.044373683631420135,-0.07590384036302567,0.12343431264162064,-0.1035904809832573,-0.04000724479556084,0.1362748146057129,-0.2465573102235794,0.1933852881193161,0.14681199193000793,0.024725046008825302,0.1317524015903473,0.05796818062663078,0.006940936669707298,-0.02915295399725437,-0.018507739529013634,-0.09597785025835037,-0.07701454311609268,0.05604630336165428,-0.006585515569895506,0.024257874116301537,0.053522560745477676],
hostel: "HB-4",
wing: "C - Wing",
room: "1053",
branch: "CSE"
}
};
const TEST_MODE = true;
const HOSTEL_POLYGON = [
{ lat: 13.128425, lng: 77.589451 },
{ lat: 13.128249, lng: 77.589476 },
{ lat: 13.128287, lng: 77.588653 },
{ lat: 13.128426, lng: 77.588660 }
];
const statusEl = document.getElementById('status');
const cameraWrapper = document.getElementById('camera-wrapper');
const startBtn = document.getElementById('start-btn');
const cardEl = document.getElementById('student-card');
const gridEl = document.getElementById('details-grid');
let videoEl;
let watchId;
let isGpsInside = false;
let recognitionLoop;
async function initApp() {
startBtn.disabled = true;
statusEl.innerText = "Downloading AI Models...";
const MODEL_URL = 'https://justadudewhohacks.github.io/face-api.js/models';
try {
await Promise.all([
faceapi.nets.tinyFaceDetector.loadFromUri(MODEL_URL),
faceapi.nets.faceLandmark68Net.loadFromUri(MODEL_URL),
faceapi.nets.faceRecognitionNet.loadFromUri(MODEL_URL)
]);
startCamera();
startGPS();
} catch (err) { statusEl.innerText = "Error loading models."; }
}
async function startCamera() {
cameraWrapper.style.display = 'block';
startBtn.style.display = 'none';
videoEl = document.getElementById('video');
const stream = await navigator.mediaDevices.getUserMedia({ video: { facingMode: 'user' } });
videoEl.srcObject = stream;
videoEl.onloadedmetadata = () => { videoEl.play(); startRecognition(); };
}
async function startRecognition() {
const labeledDescriptors = Object.keys(STUDENT_DATABASE).map(rollNo => {
const student = STUDENT_DATABASE[rollNo];
return new faceapi.LabeledFaceDescriptors(rollNo, [new Float32Array(student.descriptor)]);
});
const faceMatcher = new faceapi.FaceMatcher(labeledDescriptors, 0.55);
statusEl.innerText = "Scanning...";
const canvas = faceapi.createCanvasFromMedia(videoEl);
cameraWrapper.append(canvas);
const displaySize = { width: videoEl.clientWidth, height: videoEl.clientHeight };
faceapi.matchDimensions(canvas, displaySize);
recognitionLoop = setInterval(async () => {
const detection = await faceapi.detectSingleFace(videoEl, new faceapi.TinyFaceDetectorOptions()).withFaceLandmarks().withFaceDescriptor();
const ctx = canvas.getContext('2d'); ctx.clearRect(0, 0, canvas.width, canvas.height);
if (detection) {
const match = faceMatcher.findBestMatch(detection.descriptor);
const box = faceapi.resizeResults(detection, displaySize).detection.box;
new faceapi.draw.DrawBox(box, { label: match.toString() }).draw(canvas);
if (match.label !== 'unknown') {
checkAttendance(match.label);
} else {
statusEl.innerText = "❌ Unknown Face";
}
}
}, 500);
}
function startGPS() {
if(TEST_MODE) { isGpsInside = true; return; }
if(!navigator.geolocation) return;
watchId = navigator.geolocation.watchPosition(pos => {
const u = { lat: pos.coords.latitude, lng: pos.coords.longitude };
isGpsInside = isPointInPolygon(u, HOSTEL_POLYGON);
}, e => console.log(e), {enableHighAccuracy:true});
}
function checkAttendance(rollNo) {
if (isGpsInside) {
showSuccess(rollNo);
} else {
statusEl.innerText = "✅ Face Matched, but ❌ Outside Hostel!";
}
}
// --- THE NEW DYNAMIC CARD GENERATOR ---
function showSuccess(rollNo) {
clearInterval(recognitionLoop);
navigator.geolocation.clearWatch(watchId);
videoEl.pause();
const student = STUDENT_DATABASE[rollNo];
// 1. Set Header (Fixed Items)
const canvas = document.createElement('canvas');
canvas.width = videoEl.videoWidth; canvas.height = videoEl.videoHeight;
canvas.getContext('2d').drawImage(videoEl, 0, 0);
document.getElementById('card-img').src = canvas.toDataURL();
document.getElementById('card-name').innerText = student.name;
document.getElementById('card-roll').innerText = rollNo;
document.getElementById('card-time').innerText = new Date().toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'});
// 2. Clear previous grid items
gridEl.innerHTML = "";
// 3. Loop through Database and Create Boxes
for (let key in student) {
// Skip the items we already showed in the header
if (key === 'name' || key === 'descriptor') continue;
// Create a Box for everything else
const val = student[key];
const label = key.replace(/_/g, " "); // Convert "blood_group" -> "blood group"
const box = document.createElement('div');
box.className = 'data-box';
box.innerHTML = `
<div class="data-label">${label}</div>
<div class="data-value">${val}</div>
`;
gridEl.appendChild(box);
}
// Show Card
cardEl.style.display = 'block';
statusEl.innerText = "✅ ATTENDANCE MARKED";
statusEl.className = "success";
}
function isPointInPolygon(p, polygon) {
let inside = false;
for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
let xi = polygon[i].lat, yi = polygon[i].lng;
let xj = polygon[j].lat, yj = polygon[j].lng;
let intersect = ((yi > p.lng) != (yj > p.lng)) && (p.lat < (xj - xi) * (p.lng - yi) / (yj - yi) + xi);
if (intersect) inside = !inside;
}
return inside;
}
</script>
</body>
</html>