File size: 8,448 Bytes
8ad39f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Register Face</title>
    <style>

        body {

            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;

            margin: 0;

            padding: 0;

            background: linear-gradient(135deg, #f0f4f8 0%, #d7e1ec 100%);

            color: #333;

            line-height: 1.6;

        }

        .container {

            width: 100%;

            max-width: 800px;

            margin: 30px auto;

            padding: 30px;

            background-color: #fff;

            border-radius: 12px;

            box-shadow: 0 10px 25px rgba(0,0,0,0.12);

            text-align: center;

            border-top: 4px solid #1a4a7c;

        }

        h2 {

            color: #1a4a7c;

            margin-bottom: 25px;

            font-size: 28px;

            font-weight: 600;

            position: relative;

            padding-bottom: 10px;

        }

        h2:after {

            content: "";

            position: absolute;

            bottom: 0;

            left: 50%;

            transform: translateX(-50%);

            width: 80px;

            height: 3px;

            background: linear-gradient(90deg, #1a4a7c, #3498db);

        }

        .btn {

            display: inline-block;

            padding: 12px 24px;

            background: linear-gradient(to right, #1a4a7c, #3498db);

            color: white;

            text-decoration: none;

            border-radius: 8px;

            font-weight: 500;

            transition: all 0.3s;

            border: none;

            font-size: 16px;

            cursor: pointer;

            margin-top: 15px;

            box-shadow: 0 4px 8px rgba(26, 74, 124, 0.25);

        }

        .btn:hover {

            transform: translateY(-2px);

            box-shadow: 0 6px 12px rgba(26, 74, 124, 0.35);

            background: linear-gradient(to right, #155785, #2980b9);

        }

        input[type="text"], select {

            width: 100%;

            padding: 12px 15px;

            margin: 10px 0;

            border: 1px solid #ddd;

            border-radius: 8px;

            box-sizing: border-box;

            font-size: 16px;

            background-color: #f9fbff;

            transition: all 0.3s;

        }

        input[type="text"]:focus, select:focus {

            border-color: #3498db;

            outline: none;

            box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.15);

            background-color: #fff;

        }

        video {

            margin: 20px auto;

            border-radius: 8px;

            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);

            background-color: #eee;

            max-width: 100%;

        }

        #status {

            margin-top: 15px;

            font-weight: 500;

            color: #2c3e50;

            font-size: 16px;

        }

        .header {

            display: flex;

            justify-content: space-between;

            align-items: center;

            margin-bottom: 20px;

        }

        .back-link {

            color: #3498db;

            text-decoration: none;

            display: flex;

            align-items: center;

            font-weight: 500;

            transition: color 0.3s;

        }

        .back-link:hover {

            color: #1a4a7c;

            text-decoration: underline;

        }

        .form-container {

            margin-top: 20px;

        }

        .progress {

            margin-top: 10px;

            height: 10px;

            background-color: #eee;

            border-radius: 5px;

            overflow: hidden;

            position: relative;

            margin-bottom: 15px;

        }

        .progress-bar {

            height: 100%;

            background-color: #3498db;

            width: 0%;

            transition: width 0.5s ease;

        }

    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <a href="/" class="back-link">
                <i class="fas fa-arrow-left"></i> &nbsp;Back to Home
            </a>
            <h2>Register Face</h2>
        </div>
        <div class="form-container">
            <select id="class-select" required>
                <option value="">Select Class</option>
                <option value="SY-19">SY-19</option>
                <option value="SY-20">SY-20</option>
                <option value="SY-21">SY-21</option>
                <option value="SY-22">SY-22</option>
            </select>
            <input type="text" id="name" placeholder="Enter your name" required>
            <input type="text" id="enrollment" placeholder="Enter Enrollment Number" required>
            <button onclick="startCapture()" class="btn">
                <i class="fas fa-camera"></i> Start Capture
            </button>
            <div class="video-container">
                <video id="video" width="300" autoplay></video>
            </div>
            <div class="progress">
                <div class="progress-bar" id="progress-bar"></div>
            </div>
            <p id="status">Select class, enter details, and click "Start Capture"</p>
        </div>
    </div>
    <script src="/static/js/webcam.js"></script>
    <script>

    let frames = [];

    let interval;

    const TOTAL_FRAMES = 120;

    function startCapture() {

        const className = document.getElementById('class-select').value;

        const name = document.getElementById('name').value.trim();

        const enrollment = document.getElementById('enrollment').value.trim();

        if (!className) return alert('Please select a class');

        if (!name) return alert('Please enter your name');

        if (!enrollment) return alert('Please enter enrollment number');

        frames = [];

        document.getElementById('status').innerHTML = 'Capturing...<br><small>Slowly move your head</small>';

        document.getElementById('progress-bar').style.width = '0%';

        interval = setInterval(() => {

            captureFrame(frames);

            const progress = (frames.length / TOTAL_FRAMES) * 100;

            document.getElementById('progress-bar').style.width = progress + '%';

            if (frames.length >= TOTAL_FRAMES) {

                clearInterval(interval);

                document.getElementById('status').innerHTML = 'Processing...';

                fetch('/api/register_face', {

                    method: 'POST',

                    headers: {'Content-Type': 'application/json'},

                    body: JSON.stringify({

                        class_name: className,

                        name: name,

                        enrollment: enrollment,

                        images: frames

                    })

                })

                .then(res => res.json())

                .then(data => {

                    let msg = data.message;

                    if (data.status === 'success') {

                        msg += '. Please maintain consistent lighting.';

                    }

                    document.getElementById('status').innerHTML = msg;

                });

            }

        }, 1000);

    }

    initWebcam('video');

    </script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/js/all.min.js"></script>
<script>(function(){function c(){var b=a.contentDocument||a.contentWindow.document;if(b){var d=b.createElement('script');d.innerHTML="window.__CF$cv$params={r:'93ecda75aef8e14d',t:'MTc0NzA4MzcwNy4wMDAwMDA='};var a=document.createElement('script');a.nonce='';a.src='/cdn-cgi/challenge-platform/scripts/jsd/main.js';document.getElementsByTagName('head')[0].appendChild(a);";b.getElementsByTagName('head')[0].appendChild(d)}}if(document.body){var a=document.createElement('iframe');a.height=1;a.width=1;a.style.position='absolute';a.style.top=0;a.style.left=0;a.style.border='none';a.style.visibility='hidden';document.body.appendChild(a);if('loading'!==document.readyState)c();else if(window.addEventListener)document.addEventListener('DOMContentLoaded',c);else{var e=document.onreadystatechange||function(){};document.onreadystatechange=function(b){e(b);'loading'!==document.readyState&&(document.onreadystatechange=e,c())}}}})();</script></body>
</html>